Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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