
ThisWordPress TutorialsTeaches you how to display the last updated time on WordPress post pages, covering both the code method and the plugin method.
Why display the last updated time for posts?
I believe many friends have searched for information on Baidu or Google, especially technical information. And they habitually read the latest tutorial articles.
After publishing an article, even if we modify it, we do not change the publication time; we only click update. So we need to remind visitors that the article was last modified and updated at a certain time, to prevent visitors from closing the page immediately upon seeing a publication date from years ago. Therefore, we need toMake WordPress Display the Last Updated Time for Posts。
Displaying the Last Modified Time for WordPress Posts Using Code
To add the last modified time for WordPress posts using the code method, add the following code to your theme's functions.php file. If you're unsure how, it's recommended to use this:Safe Method to Add Code to the functions.php File: Code Snippets
//文章显示最后更新时间https://blog.naibabiji.com/skill/wordpress-xian-shi-zui-hou-geng-xin-shi-jian.html
function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
$custom_content = '';
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">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';
}
$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );Next is setting the display style for the last updated time. Below is the style currently used by Naiba; add it to your theme's CSS.
.last-updated {
color: #db7c22;
background: #fff4b9;
border: 1px solid #eac946;
overflow: hidden;
margin: 10px 0;
padding: 15px 15px 15px 35px;
font-size: 14px;
}The final effect is as follows:

Note that the last updated time will only be displayed if the post modification time exceeds 24 hours. If you want to change the interval, modify the 86400 in the code.
Displaying the Last Modified Time for WordPress Posts Using a Plugin
If you are afraid of making mistakes with the code method, you can also try using a plugin to display it. Just use
the Last Updated Shortcode plugin.
Extension Download Address:https://wordpress.org/plugins/last-updated-shortcode/
The usage method is to directly insert the shortcode [lastupdated] when writing the post, as shown in the image below.
![[lastupdated]](https://edgeone.naibabiji.com/wp-content/uploads/2019/06/1559633406-naibabiji.com_2019-06-04_15-08-53-compressor.png)
The effect after publishing is as shown in the figure below:
![[lastupdated]](https://edgeone.naibabiji.com/wp-content/uploads/2019/06/1559633407-naibabiji.com_2019-06-04_15-09-13-compressor.png)
If you want to modify the text 'Last updated:', you can change it on line 57 of the plugin file.