Archived topic
How to add last modified date to bottom of posts?
8 replies · Started by Kevin on May 20, 2017
Hey, quick question here. If I wanted to have this display at the bottom of my posts, how would I do it?
This post was last updated on [date post was last modified].
Hi Kevin,
Would this display on single posts only, or the blog as well?
Let me know :)
Apologies on the slow response! This would be for single posts only, no archive, category, or pages.
Try this in the After Content hook in GP Hooks:
<?php if ( is_single() ) {
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="updated" datetime="' . esc_attr( get_the_modified_date( 'c' ) ) . '" itemprop="dateModified">' . esc_html( get_the_modified_date() ) . '</time>';
echo 'This post was last updated on ' . $time_string;
}
} ?>
Hey Tom!
Thanks, but question:
Here's the code in 'After Content'
http://i.imgur.com/kZfUhjL.png
And here's the display:
http://i.imgur.com/tSZj0xP.png
Any ideas?
I have Execute PHP checked, btw.
I just edited the code above - can you try again?
All good, Tom. Thanks so much for the help!
You're welcome :)