How to show something if a post is published today?
Like this:
The Post. _new_
The Post. _old_
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.
}
current_time()
instead of date()
, otherwise you'll have a mismatch if server and wordpress timezone are different