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

by | Last Updated: Feb 7, 2018 | Blog, Divi theme

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: Feb 7, 2018”. The date (Feb 7, 2018) 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. This way your blog will look more professional.

5 Free WordPress Plugins You Should Use

Divi Theme Design Services

Share This