Display the Last Updated Date of Your Posts in WordPress

Display the Last Updated Date of Your Posts in WordPress

Would you like to display the last updated date for your posts in WordPress? A few sites consistently update their posts and might want to show users when the article was last updated. In this article, we will tell you the best way to effectively display the last updated date of your posts in WordPress.

When You Need Last Updated Date for Posts in WordPress?

Most WordPress themes ordinarily show the date when a post was last distributed. This is fine for most online journals and static sites.

Notwithstanding, WordPress is additionally used by sites where old articles are consistently updated (like our own). This last updated date and time is significant information for those distributions.

The most widely recognized model is news sites. They often update old stories to show new turns of events, add amendments or media files. If they just added the distributed date, then their users would miss those updates.

Numerous famous sites and sites don’t show any date on their articles. This is a terrible practice and you ought to never eliminate dates from your blog entries.

Having said that, how about we perceive how to handily display last updated date for your posts in WordPress.

Displaying Last Updated Date in WordPress

This instructional exercise expects you to add code to your WordPress files. If you haven’t done this before, then we prescribe you to take a gander at our aide on the best way to copy glue code in WordPress.

Method 1: Show Last Updated Date Before Post Content

You should add this code to your theme’s functions.php file or a site-specific plugin.

function wpb_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">Last updated on '. $updated_date . ' at '. $updated_time .'</p>'
}
    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );

This code verifies whether a post’s distributed date and last modified dates are different. If they are, then it displays the last modified date before the post substance.

You can add custom CSS to style the appearance of the last updated date. Here is a little CSS that you can use as a starting point:

last-updated {
    font-size: small;
    text-transform: uppercase;
    background-color: #fffdd4;
}

Method 2: Add Last Updated Date in Theme Templates

This method expects you to alter specific WordPress theme files. Numerous WordPress themes now use their own layout labels which define how these themes show post meta information like date and time.

Also see: How to Embed a Google Form in WordPress

A few themes additionally use content layouts or format parts to display posts.

Barely any less complex themes will use single.php, archive.php, and other format files to show content and meta information.

You will be looking for the code answerable for displaying the date and time. You can then either supplant that code with the following code or add it just after your theme’s date and time code.

$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
echo "<p>Last modified on ";
the_modified_time('F jS, Y');
echo " at ";
the_modified_time();
echo "</p> "; }

We trust this article assisted you with learning how to display last updated date of your posts in WordPress.

Leave a comment

Your email address will not be published. Required fields are marked *