in ,

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

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' ) . ' ' . et_pb_get_the_author_posts_link() . '';

if ( in_array( 'date', $postinfo ) ) {
if ( in_array( 'author', $postinfo ) ) $postinfo_meta .= ' | ';
$postinfo_meta .= 'Last Updated: ' . esc_html( get_the_modified_date( wp_unslash( $date_format ) ) ) . '';

}

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. As for me, I have only this code in my functions.php file. So for me the whole file looks the following way:

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.

Full Stack WordPress Designer and DeveloperDinar M Islam

Full Stack WordPress Designer and Developer

M: 088 019 24239141

E: hello@dinarmislam.com

 Dinar M Islam on Freelancer.comHire me on Freelancer.com

What do you think?

0 points
Upvote Downvote

Written by Dinar M Islam

More than 6+ years experience in web development specially on wordpress design and development. Making website that will sell your target. Writing and sharing knowledge about wordpress development in leisure time.

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Loading…

0

Comments

0 comments

Free Divi Consultant Layout Pack

Free Divi Consultant Layout Pack

Do I Need a Professional Photographer for My Website?

Do I Need a Professional Photographer for My Website?