Archived topic
Post "Updated on" to reflect ModifiedTime
10 replies · Started by Ivaylo on December 30, 2022
Hi,
I'm using this code:
add_filter( 'generate_post_date_output','tu_add_to_post_date' );
function tu_add_to_post_date( $output ) {
return '<span class="date-label">Updated on </span>' . $output;
}
to show the date the post is updated. But it shows the published time ( PublishedTime ) instead the one I updated the post ( which I can see in ModifiedTime )
See the attached screenshot:
Link for the image/screenshot: https://e1.pcloud.link/publink/show?code=XZNn0mZ8wL2REg5ISfStyBQwPmDC0xkJ4tX
Hi there
can i see the issue on your site ?
Sure, link is below:
I just updated this post ( 30.12.2022 ), but it still showing the date 22.12.2022 when I edited the post and hit Publish instead of Update.
I want to show the date the post was updated as it is noted in ModifiedTime in the schema/dev tools.
If you use the snippet provided here:
https://docs.generatepress.com/article/generate_post_date_show_updated_only/
Then GP Will only output a single date, either the published date or if the post has been modified it will show the updated date.
So I should place all of the following in my functions.php:
add_filter( 'generate_post_date_output','tu_add_to_post_date' );
function tu_add_to_post_date( $output ) {
return '<span class="date-label">Updated on </span>' . $output;
}
add_filter( 'generate_post_date_show_updated_only', '__return_true' );
Because I want to have "Updated on" before the date.
Is there a more elegant and shorter filter function for the above two?
Using those 2 snippets are as elegant as it gets :)
Thanks! Happy Holidays!
And Happy Holidays to you :)
