Do you want to display last updated date in GeneratePress theme? If you are looking for a simple guide, keep reading this article. We will show you how to do so with and without a WordPress plugin.
But before going further, let’s see why displaying the last updated date is essential for SEO.
Table of Contents
Why You Should Display Last Updated Date in Articles
Displaying the last updated date in articles serves several vital purposes, addressing both user needs and SEO considerations:
- Transparency and Trust: Including the last updated date provides transparency. Readers can immediately see when the information was last verified or revised, which builds trust. Knowing that content is actively maintained reassures readers that they’re accessing current, reliable information.
- Relevance and Accuracy: Information can become outdated, particularly in fast-evolving fields like technology or health. Displaying an update date allows readers to assess the article’s relevance and accuracy at a glance. This is crucial for ensuring that the content remains valid and not misleading.
- SEO and User Experience: Search engines like Google favor fresh, updated content. An updated article might rank higher in search results as it’s perceived as more relevant. From a user experience perspective, knowing when content was last updated helps users decide quickly if it’s worth reading or if it’s likely outdated.
- Content Management and Version Control: For content creators, especially in team settings, knowing when content was last updated aids in version control and content management. This practice ensures everyone involved is working with the latest version of the content.
- Engagement and Feedback: A visible update date might encourage engagement. If readers see content is regularly maintained, they might be more inclined to comment or provide feedback, fostering a dynamic blog community or discussion.
Now you know why displaying the last updated time on your GeneratePress website is a good idea. In the next section, we will show you the best methods to do this without a hassle.
How to Display Last Updated Date in GeneratePress Theme
You can use some coding to display the last modified date in GeneratePress.
1. Coding Method
You can add code to the Elements section of GeneratePress or use a site-specific plugin like Code Snippets. This tutorial will use the Code Snippets plugin for better code handling.
Installing and activating the Code Snippets plugin on your WordPress website is the first step. Once you have done that, you can begin the process.
1.1 Always Show Last Updated Date
If you always need to display the date as the last updated time, use this snippet.
add_filter( 'generate_post_date_output', function( $output, $time_string ) {
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on: %4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
return sprintf( '<span class="posted-on">%s</span> ',
$time_string
);
}, 10, 2 );
Go to the Code Snippets plugin settings and create a new snippet. Once you have done that, you can paste and save the abovementioned core.
GeneratePress will always show the date as the last updated time when you use this snippet. It doesn’t matter if the date is published or modified.
However, based on the situation, some people must show the published or last updated date. If you plan to do it, follow the method mentioned below.
1.2 Show Published/ Last Updated Date
Here, you will get a choice. You can either show the published date or show the updated date. This is an excellent code that will display the date based on the status of the post-updation.
The code you need to use is:
add_filter( 'generate_post_date_output', function( $output, $time_string ) {
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on: %2$s</time>';
if ( get_the_date() !== get_the_modified_date() ) {
$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on: %4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
return sprintf( '<span class="posted-on">%s</span> ',
$time_string
);
}, 10, 2 );
Now, go to the Code Snippets and create a new snippet. Name the snippet and paste the code there.
If you check the website from the front end and modify the blog post, you will see the updated date. Otherwise, the blog post will show the published date.
How to Display Published and Last Updated Date in GeneratePress
Sometimes, you must display the published and updated date in the article. If you are planning to do this, keep reading this section.
The first thing you need to do is create another snippet and add some code to it.
The code you need to use is:
add_filter( 'generate_post_date_output', function( $output, $time_string ) {
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
if ( get_the_date() !== get_the_modified_date() ) {
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on: %2$s</time> | <time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on: %4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
return sprintf( '<span class="posted-on">%s</span> ',
$time_string
);
}, 10, 2 );
Once you have pasted the code, you can activate the snippet.
After activation, check the blog posts. You will see both dates in the front end.
As you can see in this section, it is no hassle and easy to do.
Conclusion
Displaying the last updated date in your blog posts can ensure the best SEO and user-friendliness. When a user sees a recent date, he might think the owner is actively updating the blog posts based on the newer information.
Similarly, search engines like Google will also show the latest updated date in the SERP, which will help you gain more CTR. Modifying this would be easy when handling a WordPress website with GeneratePress theme.
As discussed in this article, you only need to use a site-specific plugin like Code Snippets and some coding.
Which method are you going to choose?
Let us know in the comments.