How to display Latest Updated Date and Time in WordPress posts

wordpress-last-update-modified-date-time

Do you have a blog with live posts?
or Do you have some posts or articles which require frequent updates?
or else Do you have articles which are more of resources and you keep updating the same with new resources quite often?


Then its must to mention the last modified date and time or last updated date and time or show the latest update time and date for a WordPress post.

As you know most of the WordPress themes comes with Date Published in article or post page. But the WordPress blogs containing frequent updated content or resources page or live blogs etc. the last updated date time or last modified date time plays a key role.

Also this helps a lot in SEO (Search Engine Optimization) as search engines highlight or feature the most popular and recently modified or updated pages and helps you to bring the relevant traffic.

Just follow this code and update your WordPress themes files or templates accordingly.

In our case we are using Twenty Fourteen theme, so the file which we need to edit or modify is:
wp-content / themes / twentyfourteen / inc / template-tags.php

In template-tags.php page look for the following function twentyfourteen_posted_on() and modify the same as below:

function twentyfourteen_posted_on() {
	if ( is_sticky() && is_home() && ! is_paged() ) {
		echo '' . __( 'Sticky', 'twentyfourteen' ) . '';
	}

  $post_time = get_the_time('U');
  $post_modified_time = get_the_modified_time('U');
  if ($post_modified_time >= $post_time + 86400) :
	// Set up and print post meta information.
  	printf( ' ',
  		esc_url( get_permalink() ),
  		esc_attr( get_the_date( 'c' ) ),
  		esc_html( get_the_date() ), 
  		esc_attr( get_the_modified_date( 'c' ) ),
  		esc_html( get_the_modified_date() ),
  		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  		get_the_author()
  	);
  else :  
	// Set up and print post meta information.
  	printf( ' ',
  		esc_url( get_permalink() ),
  		esc_attr( get_the_date( 'c' ) ),
  		esc_html( get_the_date() ), 
  		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  		get_the_author()
  	);
  endif;

}

If you are not using Twenty Fourteen theme and have your own custom theme, then look for the specified code in the single.php page or functions.php page, mostly it would be single.php which you need to edit.

Once you are at the respective code, have the following snippet:

$post_time = get_the_time('U');
$post_modified_time = get_the_modified_time('U');
if ($post_modified_time >= $post_time + 86400) {
echo "and last modified on ";
the_modified_time('F jS, Y');
echo " at ";
the_modified_time();
}

Hope this helped fellow blogger out there, why not share your snippet in case you coded it different which meets your sites criteria.