Step-by-Step Guide to Displaying the Last Updated Date in WordPress

How to Automatically Show the Last Updated Date in WordPress Blog Posts

If you want to show the “Last Updated” date on your WordPress blog posts, this tutorial will guide you through the process of adding it automatically below the content. This is useful for both users and SEO, as it signals that your content is up-to-date and fresh.

Steps to Display the “Last Updated” Date Automatically

Follow these steps to automatically show the “Last Updated” date on your WordPress posts:

Step 1: Open Your Theme’s `functions.php` File

To start, navigate to your WordPress dashboard:

  1. Go to Appearance > Theme Editor.
  2. Select the functions.php file from the right sidebar.

Step 2: Add the Code to `functions.php`

Next, add the following code at the end of the functions.php file:


/* Display Last Updated Date on WordPress Posts */
function show_last_updated_date($content) {
    if (is_single() && is_main_query()) { // Ensure it's a single post page
        $last_updated = get_the_modified_time('F j, Y'); // Format the last modified date
        if ($last_updated) {
            $content .= '<p class="last-updated">Last updated on: ' . esc_html($last_updated) . '</p>';
        }
    }
    return $content;
}

add_filter('the_content', 'show_last_updated_date');

This code retrieves the last modified date of your post and appends it to the content. You can modify the date format by changing the argument in get_the_modified_time('F j, Y') (e.g., 'l, F j, Y' for a full weekday name).

Step 3: Customize the Appearance (Optional)

If you’d like to style the “Last Updated” date, add some custom CSS to make it look great. You can do this by adding the following CSS in the WordPress Customizer:


.last-updated {
    font-size: 14px;
    color: #777;
    margin-top: 20px;
    text-align: center;
}

To add this CSS:

  1. Go to Appearance > Customize.
  2. Select Additional CSS.
  3. Paste the above code into the text area and click Publish.

Step 4: Save Changes

After adding the code to your functions.php file and any optional custom styles, be sure to click Update File to save your changes. Then, check your posts to see the “Last Updated” date appearing automatically.

Why Display the “Last Updated” Date?

Displaying the “Last Updated” date on your blog posts has several benefits:

  • Improved User Experience: It tells readers when the post was last modified, which can make your content feel more relevant and trustworthy.
  • SEO Benefits: Search engines like Google value fresh content. By showing a “Last Updated” date, you’re indirectly indicating to search engines that your content is regularly maintained and updated.
  • Content Transparency: It helps your readers know if the content has been revised, which can encourage more engagement and trust.

Last updated on: November 30, 2024

Leave a Comment

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