Show the "Last Updated" Date on Posts
Adds "Last updated on" with the modified date at the top of posts that were edited at least a day after publishing.
Opens WPIDE on
Code
add_filter( 'the_content', function ( $content ) {
if ( ! is_singular( 'post' ) || ! in_the_loop() || ! is_main_query() ) {
return $content;
}
if ( (int) get_the_modified_time( 'U' ) - (int) get_the_time( 'U' ) < DAY_IN_SECONDS ) {
return $content;
}
return '<p class="last-updated"><em>Last updated on ' . esc_html( get_the_modified_date() ) . '</em></p>' . $content;
} );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.