Why can I not use the the_time() function in an if statement using WordPress?

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:

Read More
$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.

Related posts

Leave a Reply

2 comments

  1. 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.