• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WittySparks Logo White

WittySparks

Ignite Your Thoughts

  • Topics
  • Reviews
  • Services
  • Newsletter
WittySparks / Technology / Programming / How to display Latest Updated Date and Time in Wordpress posts

How to display Latest Updated Date and Time in WordPress posts

Updated: January 30, 2022 by Sravan K • 2 min read

WordPress last update or modified date and 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 come 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( '%3$s and is last updated on %5$s %7$s',
  		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( '%3$s %5$s',
  		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 differently which meets your sites criteria.

Related Topics

  • PHP: Is it the best Programming Language ever?
  • How To Build A Great Search Box On Your Website
  • How to make Python3 version default in Windows OS?
  • Latest Java Technologies & Trends for 2020

Topic: Programming

Profile picture for Sravan K Article by

Sravan K

Contributor at WittySparks
WittySparks Staff

Sravan is a Web enthusiast, who keeps on eye on all the latest happenings on web from AI to Web3, etc.

View all posts by Sravan K

Primary Sidebar

Featured Productivity Software

Notion logo
Notion

Notion Workspace can help you stay organized and take your productivity to the next level. Use Skillshare coupon code WITTYSPARKSFREE to watch the Notion Masterclass by Ali Abdaal for FREE.

Take Free Notion Masterclass

The Best Digital Marketing Tool

Semrush logo
Semrush

Semrush helps grow your business on your terms and gets to the top with 55+ marketing tools in 1. Get a flat 40% discount on Guru plan or Try 14-day PRO Trial.

Try Semrush for FREE

Footer

Explore Topics

  • Technology
  • Business
  • Marketing
  • SEO
  • View All Topics

Sponsors

Partnered with FreePik to use the licensed images.

turn to dhgate for smartphone

Affiliate Link Disclosure

If you make a purchase from links, we will receive a small commission. See our Affiliate Disclosure.

Follow Us

  • Facebook
  • Twitter
  • Pinterest
  • LinkedIn
  • Instagram
  • YouTube
  • RSS
  • Mastodon

Copyright © 2023 WittySparks - All rights reserved.
Hosted on Rocket.net

  • About Us
  • Contact Us
  • Privacy Policy