Showing the date of published or last updated your WordPress articles helps your visitors to know that how long back this information was published. In addition, it also boost your site’s SEO ranking as Google like it to display the last updated time and date information in posts. In this post I’ll tell you to display last updated or modified date in the posts.
Method 1: Using WordPress Theme Settings (If Available)
Most of the WP themes have built-in feature to display last modified date and time in the post. This option mostly comes with name of Meta options in themes settings. If your theme support this feature then you can enable it from themes settings.
- Log in to your WordPress Dashboard.
- Go to Appearance > Customize.
- Search for a setting related to Post Meta or Date Settings.
- Check if there is an option to display the “Last Updated” date. If available, enable it.
- Save and publish your changes.
Method 2: Modify Your Theme’s functions.php File
If your theme doesn’t have a built-in feature then you can add out custom code into your theme’s functions.php file to display the last updated date.
- Log in to your WordPress Dashboard.
- Navigate to Appearance > Theme Editor.
- Open your theme’s functions.php file.
- Copy the below code and paste it at the last of the code in your file.
// By earngrip.com
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 );