Site logo

Archived topic

Modified date is earlier than posted date when scheduling posts

3 replies · Started by Ingrid on January 15, 2021

Viewing posts 1–4 of 4

Hi!
I am displaying the published and modified dates in all my posts using the code bellow:

add_filter( 'generate_post_date_output', function( $output, $time_string ) {
    $time_string = '<time class="entry-date published" datetime="%1$s" >%2$s</time>';

    if ( get_the_date() !== get_the_modified_date() ) {
        $time_string = 'Sist oppdatert: <time class="entry-date updated-date" datetime="%3$s">%4$s</time><time class="entry-date published" datetime="%1$s">%2$s</time>';
    }

    $time_string = sprintf( $time_string,
        esc_attr( get_the_date( 'c' ) ),
        esc_html( get_the_date() ),
        esc_attr( get_the_modified_date( 'c' ) ),
        esc_html( get_the_modified_date() )
    );

    return sprintf( '<span class="posted-on">%s</span> ',
        $time_string
    );
}, 10, 2 );

The problem is that when scheduling a post it shows the modified date earlier than the published date, for example if I schedule a post for a week from now, it will show like this:

last modified 15 jan 2021 / published 22 jan 2021

How can I make the modified date show only if the date is later than the posted date?

thanks!

Thanks Tom, but this function adds only the updated date, I wanted to have both published and updated date ONLY if the updated date is older than the published date.

This archived topic is closed to new replies.