wp-content Β» themes Β» functions.php Β» Show Last Updated date πŸ“… for Posts

Show Last Updated date πŸ“… for Posts

Here is a simple code snippet that you can add to your theme functions.php file to show the “last updated” date in your posts.

function my_last_updated_date( $content ) {
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time('F jS, Y');
$updated_time = get_the_modified_time('h:i a');
$custom_content .= '<p class="last-updated entry-meta">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';
}
$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'my_last_updated_date' );

A new line will be added to the beginning of the post content if the last modified and published time is different:

image 20 1024x317 - Show Last Updated date 📅 for Posts
See also  ⚠️ What is Cross-site scripting (XSS) and How to prevent WordPress XSS attacks

Was this post helpful?

Leave a Comment

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Recommended