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

WittySparks

Ignite Your Thoughts

  • Topics
  • Reviews
  • Newsletter
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 K

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?
Previous Post: « How Social Media makes it easier to build Your Brand
Next Post: 6 Adventure Vehicles You Won’t Believe Exist »
Profile picture for Sravan K

About Sravan K

Contributor at 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 K

Primary Sidebar

Search

Exclusive Coupons

  • Moqups coupon code: WITTYSPARKS for 20% or PARTNERS50 for 50% discount.
  • WPForms coupon code: WITTYSPARKS for 50% off.
  • Serpstat coupon code: wittysparks_discount for 30% off.
  • SEO Buddy coupon code: WITTYSPARKS for 25% off.
  • Morningscore coupon code: wittysparks for 30% off for 3 months.
  • FlexClip coupon code: WITTYSPARKS for 30% off.
  • Uplead coupon code: “witty” for 30-day free trial.
  • FastestVPN coupon codes: WITTYSPARKS15 or WITTYSPARKS10 or Get up to 93% OFF.
  • Outranking.io coupon code: WITTYSPARKS50 for 50% off.

For more such offers visit our exclusive offers for SEO, Bloggers, Marketers and for Business owners.

Featured Productivity Software

Notion logo
Notion

Whether you’re a solo entrepreneur or a large team, Notion Workspace can help you stay organized and get more done. Get started today and take your productivity to the next level.

Try Notion for FREE

Footer

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 © 2023 · Hosting sponsored by Rocket.net (Affiliate link)

  • About Us
  • Contact Us
  • Privacy Policy
  • LinkedIn
  • Twitter
  • Like
  • Pinterest