How to Display Last Updated Date using Astra Theme and Elementor

WordPress, by default, displays the published date of your posts. But as we know, for SEO purposes, the last updated date or modified date of your posts is more relevant than the published date. Also, the last updated date gives a fresh feel to your content that you may have written a long time back but have recently updated it.

So if you want to display the last updated date instead of the published date, how do you do this? This simple tutorial explains how you can display the modified date of your posts instead of the published date using the Astra theme and Elementor page builder on your WordPress site.

Of course, you do not need the Elementor plugin to display the last updated date, but I am listing the steps to show the last updated date on Elementor in case you’re using this popular and highly useful plugin.

I am assuming you’re already using the lightweight Astra theme for the purpose of this tutorial.

Display Last Updated Date in Astra Theme

Before proceeding further, I advise you to create and install the Astra Child theme using the Child Theme Generator. This is because you will need to paste some code in the theme’s Functions.php file and if you paste the code in the parent theme’s PHP file, any future theme update will override the code you have inserted and you will need to repeat the process over again.

This Astra theme review reveals why it’s the best multipurpose WordPress theme around.

So it is always better to use a child theme instead of making changes to the parent theme.

Just install the Astra child theme normally from within the Appearance>Themes settings and activate it. Then copy and paste the following code into the child themes Functions.php file. This file is usually located in the following directory: public_html/wp-content/themes/astra-child.

/**
 * Display only last modified date in the post metadata.
 *
 * @param String $output Markup for the last modified date.
 * @return void
 */
function your_prefix_post_date( $output ) {
	$output        = '';
	$format        = apply_filters( 'astra_post_date_format', '' );
	$modified_date = esc_html( get_the_modified_date( $format ) );
	$modified_on   = sprintf(
		esc_html( '%s' ),
		$modified_date
	);
	$output       .= '';
	$output       .= ' ' . $modified_on . '';
	$output       .= '';
	return 'Updated on' .$output;
}
add_filter( 'astra_post_date', 'your_prefix_post_date' );

Remember to insert the code at the very end in the functions.php file of the Astra Child Theme and save the changes.

Your post meta will display the modified date with the prefix ‘Updated on‘ as you can see on this page. You can add your desired words in place of ‘Updated on’ in the third line from the end in the above snippet. What’s more, you can even remove the ‘Updated on ‘ comment entirely if you wish to display the last modified date without any prefix.

That’s it. The post meta will now show the “last updated” or “last modified” date in place of the published date.

How to Display the Last Updated Date in Elementor

Now if you’re also using the popular page builder Elementor, in combination with the Astra theme, the post created with Elementor will still not display the last updated date even after making changes to the functions.php file.

Note: You will need Elementor Pro for making theme related changes like changes to the post metadata.

So to display the last updated date, head over to the Post template that you have created. In the meta data widget, choose “custom” from the Terms drop-down in place of “date”.

Next, in custom tab, select Post Date and then click on settings (the wrench icon) to the left of Post Date. Now in the Type tab, select “Post Modified” in place of “Post Published” and apply the changes.

The Elementor-created post will now show the Last Updated date in place of the published date.

Wasn’t that simple? If you found this tutorial useful, let me know in the comments below.

Further reading: 6 Stand-out WooCommerce Features in Astra Theme

2 thoughts on “How to Display Last Updated Date using Astra Theme and Elementor”

  1. Nice post but didnt work on archive pages like /blog or category page.
    Any suggestion?
    Thanks in advance.

    1. Hello Jonei,

      Google picks the date on your post. So even if you display the published date on your homepage or archives, it will not affect the modified date displayed on search results. You can even turn off the published date entirely from the Customizer settings.

Leave a Comment

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

This page may contain affiliate links to products and services that we have tried and tested. Our affiliate relationship in no way influences our view of the product or service that we recommend on this blog. Read our Affiliate Disclosure.

WordPress SEO Made Easy!

Go from WordPress SEO zero to hero in no time. Optimize your blog's SEO, gain higher rankings, and attract more search traffic.

 

WordPress SEO eBook
No thanks, I know everything about WordPress SEO
Scroll to Top