I am trying to save the current month as a variable and then based on the value, I want it to display the full name of the month. When I use the_time() in a function, it automatically echos out it out, which I do not want.
Here's the code:
$month = the_time('M');
if($month == 'Aug') { echo 'August'; }
How can I save the value of the_time('M') in a variable to use in an if statement without it echoing out the value?
btw, I know I can use the_time() function to echo out the full name of the month, but I am using this as a test. Based on the what the_time() is, I want to display a different image that corresponds to the month.
How can I save the value of the_time('M') in a variable to use in an if statement without it echoing out the value?
Use get_the_time().
Every the_... function in Wordpress has a get_the_... equivalent that will return the value instead of echoing it.
Instead of the_time(), use the get_the_time().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With