🚀 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 Posts in WordPress

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 materials. They habitually tend to read newer tutorial articles. After we publish a post, even if we make modifications, we don't change the publication time of the post; we only click update. Therefore, it's necessary to provide a reminder to visitors, informing them when this article was last modified and updated, to prevent visitors from closing the page immediately upon seeing a publication date from years ago. So, 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:last_updatedNote 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're worried about making mistakes with the code method, you can also try using a plugin to display it. Simply use the Last Updated Shortcode plugin. Plugin 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]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.

「Naibabiji WordPress Website Building Coaching Service」—From choosing a domain and buying hosting, to installing a Theme and publishing content, I「ll coach you through every step, helping you avoid detours and reach your goal directly.

👉 Learn about the 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 QR Code to Follow

AI Website Building Assistant

🤖
Hello! I am the Naibabiji AI Assistant. How can I help you?
Quick Consultation: