Most websites display the date a post was published, and this is perfectly adequate for most static websites and blogs.

However, some websites update content on a regular basis. News sites, especially, might need to do this in order to update a breaking story with new information, corrections, images/videos, etc. Or tutorial websites might update some code, etc. ThePixelPixie, for instance, regularly updates the “Useful Sites” page.

Unfortunately, there are some websites that don’t even show a published date, and that’s just generally bad practice (here’s a nice article on WPBeginner.com about why it’s bad practice).

Luckily, adding the “last modified” date (and even time) to your theme file is pretty dang simple! And while there are multiple ways to do this, I’m going to just share the quickest and easiest (and the one I use here on ThePixelPixie.com).

For this snippet, I’m assuming that you already know how to access your theme files and that you have a very basic knowledge of the WordPress file structure. I’m also assuming that you are practicing good WordPress themeing habits by either using a ChildTheme, or only modifying a theme that you’ve created yourself. If you’re using a purchased or downloaded 3rd party theme, please make sure you’re using a child theme to make changes, or you risk getting your customizations overwritten when the theme updates.

Ok, now that that business is out of the way, simply add this to your single.php meta information area. For my theme, I have a separate meta block that I call on various template pages throughout my site, so I only have to change one file instead of a whole bunch. I’m including the full meta block for you here. Feel free to modify it for your own site.

<div class="meta-data">
	<span class="meta-author"><?php the_author_link(); ?></span>
	<span class="meta-date">
		<i class="fa fa-calendar"></i>Posted: <?php echo get_the_time('M d, Y');
		
		$u_time = get_the_time('U');
		$u_modified_time = get_the_modified_time('U');
		if ($u_modified_time >= $u_time + 86400) {
			echo " / Last modified: ";
			the_modified_time('F jS, Y');
			echo " at "; 
			the_modified_time(); 
		} ?>
	</span>
	<span class="meta-cats">Tags<?php printf('%1$s', get_the_category_list( ' ' ) ); ?></span>
	<span class="meta-comments"><i class="fa fa-comments"></i>
		<a href="<?php echo get_comments_link(); ?>">Leave a Comment</a>
	</span>
	<span class="meta-views"><i class="fa fa-eye"></i><?php echo getPostViews(get_the_ID()); ?></span>
</div>

A couple of items to note above: the <i> items are icons from FontAwesome (and this site is still on v4. You’ll want to update to v5 if you haven’t already). Also, in case you were interested, the “86400” is the number of seconds in 24 hours.

As I mentioned, there are other ways to accomplish the same thing. This is the easiest one. How do you display meta data on your posts?

Subscribe and receive my FREE eBook


4 MISTAKES You’re Making on Your Website that are Costing You MONEY!

  • This field is for validation purposes and should be left unchanged.

The Author

Save

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Ready to chat about how ThePixelPixie can help?