0

How to show something if a post is published today?

Like this:

The Post. _new_  
The Post. _old_  

1 Answer 1

1

You can use get_the_time() to get the date of the current post. Just use a format that only includes the year and date, and compare it to the current date using the current_time() function with the same format:

if ( get_the_time( 'Yd' ) === current_time( 'Yd' ) ) {
    // Post was published today.
}
1
  • 2
    Edited your answer to use current_time() instead of date(), otherwise you'll have a mismatch if server and wordpress timezone are different
    – kero
    Sep 4, 2017 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.