🚀 Is building a website too difficult? Let me guide you step by step—Learn about the 「Naibabiji WordPress Website Building Coaching Service」 →

How to Display the Last Updated Time for WordPress Posts

ThisWordPress TutorialsThis tutorial teaches you how to display the last updated time on WordPress post pages, divided into a code version and a plugin version.

Why display the last updated time of a post?

I believe many friends have searched for information on Baidu or Google, especially technical information. They habitually read newer tutorial articles. After we publish an article, even if we modify it, we do not change the publication date, only click update. Therefore, we need to provide a reminder to visitors, informing them when this article was last modified and updated, to avoid visitors closing the page immediately upon seeing a publication date from N years ago. So we need toMake WordPress display the last updated time of a post

Display WordPress post last modified time using code

Add WordPress post last modified time using the code method. Add the following code to your theme's functions.php file. If you don't know how, it is 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 .= '

Last updated on '. $updated_date . ' at '. $updated_time .'

'; } $custom_content .= $content; return $custom_content; } add_filter( 'the_content', 'wpb_last_updated_date' );
Then, set the display style for the last updated time. Below is the style currently used by Naibabiji. 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:last_updatedNote that the last updated time will only be displayed if the post modification time exceeds 24 hours. If you want to modify the interval, change the 86400 in the code.

Display WordPress last modified time using a plugin

If you are afraid of making mistakes using the code method, you can also try using a plugin to display it. Simply use the plugin Last Updated Shortcode. Plugin download address:https://wordpress.org/plugins/last-updated-shortcode/Then, the usage method is to directly insert the shortcode [lastupdated] when writing the article, as shown in the figure below.[lastupdated]The effect after publishing is as shown in the figure below:[lastupdated]If you want to modify the text 'Last updated:', you can change it on line 57 of the plugin file.

🚀 Still feeling confused after reading the tutorial? Let me guide you step-by-step instead.

「Naibabiji WordPress Website Building Coaching」 — From selecting a domain and purchasing hosting to installing themes and publishing posts, I「ll guide you through every step, helping you avoid detours and reach your goals directly.

👉 Learn about Website Building Coaching Service
🔒

Comments are closed

The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.

×
二维码

Scan to Follow