HostOnNet Blog

How to add last updated date in WordPress Posts and Pages.

To add WordPress “modified_date”, just follow the simple steps.  You just have to replace some code with the code snippet given below.  Here is the steps to edit Twenty-Seventeen theme of WordPress.

  • Just go to ‘theme’ folder within WordPress installation folder (that might be ‘public_html’ normally).
  • Move to template-tags.php file and locate the twentyseventeen_time_link function.
  • Find the old code.

$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
}

$time_string = sprintf( $time_string,
get_the_date( DATE_W3C ),
get_the_date(),
get_the_modified_date( DATE_W3C ),
get_the_modified_date()
);

return sprintf(__( '<span class="screen-reader-text">Posted on</span> %s', 'twentyseventeen' ),
'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
);

Replace with the new code given below:

if ( get_the_time() !== get_the_modified_time() )
{
$time_string = '<time class="entry-date up_post published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
$post_status='Updated on ';
}
else
{
$time_string='<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated pubpost" datetime="%3$s">%4$s</time>';
$post_status='Posted on ';

}
$time_string = sprintf( $time_string,
get_the_date( 'c' ),
get_the_date(),
get_the_modified_date( 'c' ),
get_the_modified_date()
);
return sprintf(__( '<span class="screen-reader-text">%s</span><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">%s</a>', 'Templatetoaster' ),$post_status,$time_string );

You are done. Now you can see the last updated date on your posts/pages.


About ramesh xavier

Hi I am Ramesh Xavier I have a passion for designing detailed, creative and modern websites, I have been working as web-designer for over 4 years, and have done lots of work over that time, I'm always keeping an eye on the latest trends over typography, shapes, colours, etc..
Posted in Wordpress