What I’d like to do is display the date of the first workday of a month unless it’s past, then show the next months first workday on a WordPress website using a shortcode.
I’m thinking this could be done as a function in the WordPress Theme’s functions.php file. I have a shortcode function I’ve been using to show the current year for Copyright notices in the footer.
function year_shortcode() {
$year = date('Y');
return $year;
}
add_shortcode('year', 'year_shortcode');
And I have a PHP function that is supposed to show the first weekday of a month and year.
date('d-m-Y', strtotime('weekday february 2016'))
But I don’t know how to put it all together. I was thinking something like this:
- Get the current day, month and year variables.
- Put them in the PHP date above.
- If the resulting date is past the current date add 1 to the month and run again.
- Put the result in the shortcode function.
This is the first time I’ve posted on here and I’m not a programmer. Please be kind and thanks in advance for any help you can offer.
2
Answers
I think I figured this out with improved code and the conditional I requested in #3 above.
I'm using the PHP relative formats (first weekday of this month/first weekday of next month) instead of dates. Then the conditional if the result is in the past, get the first workday from the next month. Note: the 0:00 is so just the date is being compared and not the time.
You can put it all together like this.
and use this [year] shortcode anywhere.