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.
Use
get_the_time()
.Every
the_...
function in WordPress has aget_the_...
equivalent that will return the value instead of echoing it.Instead of
the_time()
, use theget_the_time()
.