Search

How to Display Last Updated Date in Divi Post Meta (without Extra Plugin)

Highlighting the updated date in an article is a wonderful idea because it caters to what users naturally prefer. We all want the latest and most relevant information, especially in fast-paced fields like tech or news. Knowing the last updated date helps readers gauge the freshness and accuracy of the content they’re reading.

By default, Divi only shows the published date for articles. However, fear not! In this post, we’ll guide you through adding the last updated date to your Divi post meta. Whether you want to replace the published date with the last updated date or display both side by side, we’ve got you covered.

And the best part? No need for extra add-ons or plugins!

Displaying Last Updated Date in Divi Post Meta

To implement this tutorial, you’ll need to integrate custom code into your website. The quickest method involves adding the code snippet at the end of your theme’s functions.php file. Access this file by navigating to Appearance → Theme File Editor and selecting the functions.php file from the theme file list.

It’s advisable to create a backup of your WordPress files, either through backup plugins or the built-in backup feature of your hosting service. Alternatively, you can opt for a safer method to add custom code to your website.

Once you’ve determined the location for the custom code, the next step is to select the preferred method for displaying the last updated date of your articles and then copy the corresponding code.

By Swapping the Published Date with the Last Updated Date

The first option involves replacing the publish date with an updated date. Initially, the published date will be displayed, but upon making updates to the post, it will automatically switch to the last updated date. Below is the corresponding code for this option.

function wpp_last_updated_date( $the_date ) {
    if ( 'post' === get_post_type() && !is_admin() ) {
        $the_time      = get_post_time( 'His' );
        $the_modified  = get_post_modified_time( 'His' );
        $last_modified =  sprintf( __( 'Last updated %s', 'Divi' ), esc_html( get_post_modified_time( 'M j, Y' ) ) );
        $date          = $the_modified !== $the_time ? $last_modified : get_post_time( 'M j, Y' );
 
        return $date;
    }
 
    return $the_date;
}
add_filter( 'get_the_date', 'wpp_last_updated_date' );
add_filter( 'get_the_time', 'wpp_last_updated_date' );

The provided code will substitute the default published date with the last modified date of your post and append “Last Updated” before the date. If you wish to customize the displayed text, simply locate and replace “Last Updated” with your preferred text within the code.

Remember to click the Update File button to save and apply the changes. Upon completion, you’ll notice the specified text followed by the last modified date in your post meta.

The example above utilizes a Post Title Module to showcase the title, author, date, and category of the article within a single post layout.

Additional: Add Specific Time to the Date

To provide a more detailed time alongside the date, you can achieve this by locating the following line of code:

get_post_modified_time( 'M j, Y' )

Then, adjust the parameter to include a 12-hour format of the hour, accompanied by an AM or PM indicator, following the last updated date.

get_post_modified_time( 'M j, Y \a\t g:iA' )

Below is the illustration of the last updated date with a more detailed time.

By Displaying Both the Published and Last Updated Date

The alternative option is to exhibit both the published date and the last update on the post meta. Below is the code required to accomplish this task:

function wpp_last_updated_date( $the_date ) {
    if ( 'post' === get_post_type() && !is_admin() ) {
        $the_time      = get_post_time( 'His' );
        $the_modified  = get_post_modified_time( 'His' );
        $last_modified = sprintf( __( 'Last updated %s', 'Divi' ), esc_html( get_post_modified_time( 'M j, Y' ) ) );
        $published     = sprintf(__( 'Published on %s', 'Divi' ), esc_html( get_post_time( 'M j, Y' ) ) );
        $date          = $the_modified !== $the_time ? $last_modified .' | '. $published : $published;
 
        return $date;
    }
 
    return $the_date;
}
add_filter( 'get_the_date', 'wpp_last_updated_date' );
add_filter( 'get_the_time', 'wpp_last_updated_date' );

After updating the file with the provided code, reload your article to observe how they align together within the post meta.

Additional: Add Detailed Time to the Last Updated Date

To include a more precise time alongside the last modified date, you can achieve this by locating the following line of code:

get_post_modified_time( 'M j, Y' )

Then, substitute the parameter to incorporate a 12-hour format of the hour, along with an AM or PM indicator, following the last updated date.

get_post_modified_time( 'M j, Y \a\t g:iA' )

After updating the file, you’ll have a specific time displayed alongside the updated date for your article.

The Bottom Line

Let’s enhance your readers’ experience by ensuring they always have access to the most current information. With our step-by-step guide, you’ll effortlessly incorporate the last updated date into your Divi post meta, without the hassle of installing additional add-ons or plugins.

This page may contain affiliate links, which help support our project. Read our affiliate disclosure.
Hendri Risman

Hendri Risman

Hendri is a WordPress expert and a writer staff at WPPagebuilders. He writes solutions on how to get things fixed in WordPress a lot. Mostly without involving a plugin.
Want to save yearly expense up to $219? why not?

Leave a Comment

Save your Divi assets to the cloud and access them from anywhere.