Automatically add last modified date and time to your blog posts
In Wordpress, there's no simple WordPress Plugin for newbies like me, and my chosen/purchased template doesn't have that function built in. I just want my reader to be able to have an easy way to see when I've last made any changes to any of my posts. I identified the need for such function over here:
So, after a bit of poking around and some edits to my postinfo.php, I believe I nailed it. Here is my story...
It all began with my failed attempt at getting this 2008-vintage Addin called "Last Modified" to work the way I wanted it to:
A bit of Googling around, and discovered a user's comments basically saying that's the old school way:
so I deactivated and deleted the "Last Modified" Plugin and moved onward, reading this related WordPress articles:
I didn't quite catch on to the tip about avoiding repeating the date/time twice, but that's OK, I like the way it is, actually, always showing the last edited time, even if no changes were made.
I then headed over here for the date syntax:
and read about "The Loop" here:
Finally, ready to
break things code!
1) Told WordPress to change my default date format
I wanted to add the time to everywhere the date shows, adding 2 digit hours to keep columns aligned, see screenshot.
This is done through the /wp-admin Dashboard:
Appearance, Theme Options, General Settings, General Tab, Date format
M j, Y
D M d, Y h:i
2) Next, I edited postinfo.php
adding this 1 line (in green) to the end of postinfo.php, just before these existing last 2 lines:
<p>Last Edited: <?php the_modified_date('M j, Y'); ?> at <?php the_modified_date('g:i a'); ?></p>
<?php }; ?>
3) Try try again, tweak until it's right!
I then tweaked and tweaked (and broke and unbroke) my site, until I settled on this new one line, achieving decent column alignment,
<p>-Edited <?php _e('by','Polished'); ?> <?php the_author_posts_link(); ?> on <?php the_modified_date('D M d,'); ?> <?php the_modified_date('Y h:i a'); ?></p>
<?php }; ?>
That's it, new row lined up nicely under the default theme's post details row, only there for readers who have actually clicked on an article they wish to review. Not sure yet whether I'd want this clutter on main site, we'll see.
PS: Wed is much wider than Fri, and Aug is wider than Jul, so it doesn't always line up perfectly, seen below: