Archived topic
Modified date is earlier than posted date when scheduling posts
3 replies · Started by Ingrid on January 15, 2021
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!
Hi there,
This filter may be better than that one: https://docs.generatepress.com/article/generate_post_date_show_updated_only/
It will display the updated date only if it's later than the published date. The only change you may need to make is adding the Sist oppdatert: text using some CSS:
.updated-date:before {
content: "Sist oppdatert: ";
}
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.
In that case, the CSS in the following article is all you should need: https://docs.generatepress.com/article/show-the-updated-post-date/