In my theme, I'd like to display the publish date and (only) if the post was updated after the publish date, also display the updated date. The code in my theme now looks like this:

*/ stuff above here to display publish date, then do this stuff to see if updated */
if ( get_the_date() != get_the_modified_date() )
        printf( __( '<br>Updated: <time class="entry-date" datetime="%1$s">%2$s</time>', 'splatone' ),
        esc_attr( get_the_date( 'c' ) ),
        esc_html( get_the_date() )

If the post was published and updated on the same day, I'd rather not show the updated line, but it currently is. How can I compare the dates so that I only get it if the date has changed and not just the time?


get_the_date() and get_modified_date() don't return time values: so, if you change your conditional statement to the below, it should work:

if ( get_the_modified_date() > get_the_date() )

Now if the updated date is greater than the original publish date(by one day), the if statement is true.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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