How to Add “Last Updated” Text to Your Blog Posts Date

by Last Updated: Oct 19, 2023Blog, Divi theme

NOTE: I have not tested if this trick works with themes other than Divi too. However, with Divi it works without any problems.

This time I’m going to share with you a small tweak that I’m using on all of my blogs that are running on the Divi theme. You can see it even on this Divi blog, just check the meta information below the title of this article. I have written there “Last Updated: Oct 15, 2020”. The date (Oct 15, 2020) is generated automatically by the post’s published date or when it was last updated. However, the “Last Updated:” string before it was added manually by myself.

 

Last Updated Posts Meta

 

Now I will explain you how you can do it. It is pretty simple.

The only thing that you need to do is to add the following code to your child theme’s functions.php file. It would work even without a child theme, but you should always use a child theme so that your changes do not get lost when you update Divi to a newer version (for a tutorial on how to create a child theme for Divi, check this article).

So here’s the code that you need to add to your child theme’s functions.php file:

if ( ! function_exists( 'et_pb_postinfo_meta' ) ) :
function et_pb_postinfo_meta( $postinfo, $date_format, $comment_zero, $comment_one, $comment_more ){
$postinfo_meta = '';

if ( in_array( 'author', $postinfo ) )
$postinfo_meta .= ' ' . esc_html__( 'by', 'et_builder' ) . ' <span class="author vcard">' . et_pb_get_the_author_posts_link() . '</span>';

if ( in_array( 'date', $postinfo ) ) {
if ( in_array( 'author', $postinfo ) ) $postinfo_meta .= ' | ';
$postinfo_meta .= '<span class="published">Last Updated: ' . esc_html( get_the_modified_date( wp_unslash( $date_format ) ) ) . '</span>';

}

if ( in_array( 'categories', $postinfo ) ) {
$categories_list = get_the_category_list(', ');

// do not output anything if no categories retrieved
if ( '' !== $categories_list ) {
if ( in_array( 'author', $postinfo ) || in_array( 'date', $postinfo ) ) $postinfo_meta .= ' | ';

$postinfo_meta .= $categories_list;
}
}

if ( in_array( 'comments', $postinfo ) ){
if ( in_array( 'author', $postinfo ) || in_array( 'date', $postinfo ) || in_array( 'categories', $postinfo ) ) $postinfo_meta .= ' | ';
$postinfo_meta .= et_pb_get_comments_popup_link( $comment_zero, $comment_one, $comment_more );
}

return $postinfo_meta;
}
endif;

 

And remember that the functions.php file needs to start with <?php and end with ?>. As for me, I have only this code in my functions.php file. So for me the whole file looks the following way:

 

<?php
if ( ! function_exists( 'et_pb_postinfo_meta' ) ) :
function et_pb_postinfo_meta( $postinfo, $date_format, $comment_zero, $comment_one, $comment_more ){
$postinfo_meta = '';

if ( in_array( 'author', $postinfo ) )
$postinfo_meta .= ' ' . esc_html__( 'by', 'et_builder' ) . ' <span class="author vcard">' . et_pb_get_the_author_posts_link() . '</span>';

if ( in_array( 'date', $postinfo ) ) {
if ( in_array( 'author', $postinfo ) ) $postinfo_meta .= ' | ';
$postinfo_meta .= '<span class="published">Last Updated: ' . esc_html( get_the_modified_date( wp_unslash( $date_format ) ) ) . '</span>';

}

if ( in_array( 'categories', $postinfo ) ) {
$categories_list = get_the_category_list(', ');

// do not output anything if no categories retrieved
if ( '' !== $categories_list ) {
if ( in_array( 'author', $postinfo ) || in_array( 'date', $postinfo ) ) $postinfo_meta .= ' | ';

$postinfo_meta .= $categories_list;
}
}

if ( in_array( 'comments', $postinfo ) ){
if ( in_array( 'author', $postinfo ) || in_array( 'date', $postinfo ) || in_array( 'categories', $postinfo ) ) $postinfo_meta .= ' | ';
$postinfo_meta .= et_pb_get_comments_popup_link( $comment_zero, $comment_one, $comment_more );
}

return $postinfo_meta;
}
endif;
?>

This trick can be helpful for you if you want to make some updates to the blog posts on your blog occasionally and show the last updated date on them. This way your blog will look more professional.

It is a good practice to update your blog posts from time to time, because Google likes fresh content. It can also increase your CTR on Google if the people searching see that the date of your article is recent. In my experience, when I’m searching for something on Google, I’m more likely to click on the result that has the most recent publish date.

For more Divi & WordPress tutorials like this one, you can subscribe to my newsletter.

5 Free WordPress Plugins You Should Use

Banner Blue Biz Child Theme

Andrej

Author: Andrej

WordPress expert. Divi user since 2014. I blog about WordPress and Divi, my favorite WordPress theme. When I’m not working with WordPress or writing an article for this blog, I’m probably learning Italian. You can read more about me here.