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

WittySparks

Ignite Your Thoughts

  • Topics
  • Reviews
  • Subscribe
WittySparks / Technology / Programming / How to display Latest Updated Date and Time in Wordpress posts
WordPress last update or modified date and time

How to display Latest Updated Date and Time in WordPress posts

Programming November 10, 2014 by Sravan Kumar Kandagatla

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.

Appreciate your opinion on this topic on social media by tagging us @wittysparks
  • LinkedIn
  • Twitter
  • Like
  • Pinterest

Related Topics

  • Modifying WordPress to Allow website Authors to choose the Related Posts
  • PHP: Is it the best Programming Language ever?
  • Want to know if your PHP pages in Google index worthy? Here are a few core aspects to know
Launch Offer
Rocket.net - Managed WordPress hosting
Rocket.net - Managed WordPress hosting
$1 for first month, $25/month

A highly secured WordPress hosting platform powered by Cloudflare enterprises with customized services for agencies, eCommerce, and small businesses.

  • PageSpeed Guarantee
  • Ultra Secure Platform
  • FREE Migrations
  • Automatic Updates
Try for $1.00 Our Review
We earn a commission if you make a purchase, at no additional cost to you.

Our Favorite Tools

Semrush - SEO and Marketing Tools
Semrush - SEO and Marketing Tools
$119.95/mo
Try for FREE Our Review
Semrush - SEO and Marketing Tools
Lasso - All-in-one Affiliate Marketing Plugin for WordPress
$29/month
Start Free Trial Our Review
Semrush - SEO and Marketing Tools
Grammarly - AI-powered writing assistant
$12.00 / month
Try for FREE Our Review
Previous Post: « How Social Media makes it easier to build Your Brand
Next Post: 6 Adventure Vehicles You Won’t Believe Exist »

Reader Interactions

Profile picture for Anonymous

About Sravan Kumar Kandagatla

Founder of WittySparks
WittySparks Staff

Sravan is a highly experienced web designer, user experience designer and developer. You can connect with him on Twitter or LinkedIn and initiate a chat.

View all posts by Sravan Kumar Kandagatla
  • LinkedIN
  • Twitter
  • Pinterest
  • Facebook
  • Instagram

Comments

  1. Profile picture for Vichu RoxxVichu Roxx says

    March 14, 2017 at 6:11 pm

    this code resulted in a fatal error of website can u please rechek the code

Footer

Search

Exclusive Coupons

  • Moqups Review - Use coupon code “WITTYSPARKS" for 20% off or "PARTNERS50" for 50% discount on all plans.
  • Serpstat Review - Use coupon code "wittysparks_discount" for 30% off.
  • WPForms Review - Use coupon code "WITTYSPARKS" for 50% off.
  • WPPayForm Review - Use coupon code "wittysparks" for 10% to 40% off.

Affiliate Disclosure

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

Sponsors

Partnered with FreePik to use the licensed images.

turn to dhgate for smartphone

Follow Us

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

Copyright © 2022 · Hosting sponsored by Rocket.net (Affiliate link)

  • About Us
  • Contact Us
  • Privacy Policy
  • Affiliate Disclosure