WP plugin: Post Updated

posted on February 22, 2005

Time for a new WordPress plugin! Post Updated is a simple fellow: it displays the last modified date and time for a post (that is, if later than the original post date). Useful for providing a “last updated” flag to your posts.

To install and use Post Updated, download the zip file, extract post-updated.php, upload this to your wp-content/plugins/ directory, and activate the plugin in WordPress. The function post_updated() must be used in The Loop.

Usage:

<?php post_updated('format', hours, 'before', 'after', gmt, display); ?>

Parameters:

format
(string) Format modified date/time is to display in. Defaults to date and time formats configured in your WordPress options. For help in modifying, see the PHP manual on date and time format parameter strings.
hours
(integer) Number of hours allowed between original post timestamp and modified timestamp before displaying modified date/time. Defaults to 3.
before
(string) Text to display before modified date/time. Defaults to 'Last updated: '
after
(string) Text to display after modified date/time. There is no default.
gmt
(boolean) Use Greenwich Mean Time timestamp for posts (TRUE), or use the standard timestamp (FALSE). Defaults to FALSE.
display
(boolean) Display modified time/date (TRUE), or return modified timestamp to be used in PHP (FALSE). Defaults to TRUE.

Examples:

<?php post_updated('', 6, '<span class="meta">Last modified: ', '</span>'); ?>

Displays modified date/time in default format if modified time is more than 6 hours after original post time; placed in a span tag using the css class ‘meta’ and prefixed with the text “Last modified: ”.

<?php post_updated('M j, Y', 24, '<p>Updated: ', '</p>'); ?>

Displays modified date for post if modified time is more than 24 hours after original post time. Display format is “Updated: Feb 23, 2005″ (in a paragraph tag).

Author: Kaf Oseo
Categories: WordPress
Comments: (49) · Leave a comment · Comments RSS2

Lorelle
Comment » February 24, 2005 @ 9:39 am

This is great but I’m curious how it compares with this last-modified plugin? I use this and it works for me. What’s I’d really like is to modify WordPress to recognize “last-modified” as the sort order rather that the post date, since I don’t run a traditional blog.

Thanks.

Kaf
Comment » February 24, 2005 @ 11:10 am

It varies from Nick’s plugin (which I hadn’t known about before, thanks) in that you can specify not just the format for the date/time, but also:

* A “grace” period from the original post timestamp. If you tend to make grammatical changes after posting an article but don’t want this to set off the plugin, you can tell it to allow for some amount of time (by hours).
* Before and after text.
* Use regular or GMT time.
* Either display the modified timestamp or return for coding use.

What you’re looking for is way over the head of my little plugin here. But I’ll dig through the WordPress core to see what it would take.

Lorelle
Comment » February 25, 2005 @ 11:23 pm

With Nick’s plugin, you can modify the date and time – it works on PHP time/date funcitions. But I like what’ you’ve done with this. I might just have to replace his with yours…hee hee.

Thanks for the great work and the lovely site.

Kaf
Comment » February 26, 2005 @ 12:49 am

Thanks for the kind words, fellow WP traveller. Like Nick’s plugin, Post Updated also acccepts PHP date format strings, defaulting to WordPress settings if you choose not to play with them.

In regards to Nick, I’ve a lot of respect for him and his work. Why else would I have stolen some of his code for my first plugin? Sure there’s a lot of possible reasons, but trust me, it was the respect.

Sean Nordbo
Comment » March 9, 2005 @ 6:51 am

Probably a greta plugin but can’t get it to work :-/ Uploaded the plugin file, activiated it and added Updated: ‘, ”); ? > within the loop. Got no errors … just that nothing happens even if I update a post.

Something I’ve missed? Any suggestions?

Thanks :-)

Kaf
Comment » March 9, 2005 @ 1:36 pm

Sean,

Checking your site, from the “Updated” elements showing on some posts it looks like you worked out the kinks in setting up the plugin. Good stuff.

Gary
Comment » April 27, 2005 @ 6:09 pm

Do you know of anyway to modify the ‘last updated’ date? I moved a bunch of posts over and had to fix the categories. Now they ally show as having been updated recently. I would really like to restore them back to their original date.

Kaf
Comment » April 27, 2005 @ 8:38 pm

Gary, I sent you an email.

Kaleo Silva
Comment » July 17, 2005 @ 11:07 pm

Re: Lorelle

You can change the sort order to use the post_modified field. Check this old wiki page for instructions. Note: the $allowed_keys array is now inside “/wp-includes/classes.php” (WP 1.5).

Derek
Comment » December 31, 2005 @ 10:36 am

I’ve been looking for some way to display the modified times of pages instead of the created time. This did the trick. Thank you!

Makenshi
Comment » January 24, 2006 @ 8:58 am

Does this plugin work for pages as well as blog entries?

Kaf
Comment » January 24, 2006 @ 9:47 am

Does this plugin work for pages as well as blog entries?

Yes.

Harlim
Comment » January 30, 2006 @ 10:25 am

Hello, I really need help. I am on WP2.0. Downloaded the package, activated it in the control panel. Then? I don’t understand “the loop” thing. Any more detail instructions? Thanks.

Kaf
Comment » February 28, 2006 @ 3:08 pm

Info on The Loop:

http://codex.wordpress.org/The_Loop

If you know anything about WordPress Template Tags and how to use them in your templates, then you’ll know how to put this (and other such template taggish) plugin into operation.

Brian G
Comment » March 3, 2006 @ 9:37 am

works great.
thanks.

aketus
Comment » March 7, 2006 @ 5:25 am

Hey there,

I’m trying to work out a way where I can use such a script, but for it to only appear on the main site (the blog default page), but put a universal ‘this site was modified’ rather than a ‘this post was modified’. Is this possible?
Say I updated the main page’s latest post on 3rd March, but I updated another separate page on the blog on the 4th March. How do I get the main page to ignore the ‘post updated’ and print only the latest overall update on *any* page?
I added the script to the page.php, it displays the update for each individual page, but I would like to just have one on the main that takes the date/timestamp from whatever page was last updated. Is that easy to do, can I edit the existing script or do I need a totally different sort?
Hope that makes sense.

Kaf
Comment » March 8, 2006 @ 12:24 am

aketus, it makes perfect sense. But my plugin would not work here, and I don’t know of one offhand that does what you’re looking for.

However, there’s not much involved in getting this info and displaying it, so I’ll email you a bit of code which accomplishes what you’re after.

Jim
Comment » May 9, 2006 @ 7:09 am

Just what I was looking for. Definitely saved me from coding. Thanks, it works great for me.

Jim
Comment » May 10, 2006 @ 10:14 am

I see where you said this will work for Pages, too. I’m using a theme called Simpla which doesn’t have a page.php. Could that be the problem?

Geren
Comment » June 27, 2006 @ 9:11 am

Does this also work when a post is commented on? I’d like to have a way to have a post date/time updated when someone makes a comment to a post.

Thanks!

Andy
Comment » August 1, 2006 @ 10:21 am

This plugin worked locally for me (php5) however when I tried it only (php4) nothing is displayed. Do you know if php4 is supported?

Martin Daugaard Stevnhoved
Comment » August 30, 2006 @ 4:47 pm

I would like my posts to show me the real time and my pages to show me the time it is updated. How do I do that in the template. I don’t want both times to be shown. Is it possible?

Matt
Comment » October 11, 2006 @ 6:52 pm

Is there an easy way to get the same functionality working outside The Loop? I’d like to include the modified date in the footer.

Thanks!

stagiaire
Comment » November 28, 2006 @ 8:37 pm

I’m looking for a plugin that lists the last 5 updated entries, just like the recently posted entries list. Is it possible to create such a list with this plugin, or could you create something like that?

directorio
Comment » December 24, 2006 @ 2:00 pm

Works well in my site and blog. I run it on PHP 5 so no problems. Thanks!

mart
Comment » January 8, 2007 @ 1:22 pm

Hi there! This plugin is sort of what I’m looking for but not quite, I was wondering if you knew of anything that could help. Basically, I want to have a link list of pages on my home page and when they were last updated, like this:

Page 1 – 08/01/07
Page 2 – 23/12/06
Page 3 – 13/11/06

Then say Page 3 gets updated, its link would pop up to the top of the list.

I realise this is probably pretty specific functionality, so I understand if you’re unable to help in this regard, I was just wondering if your plugin could possibly be modified to do it. Thanks!

Jonathan
Comment » February 9, 2007 @ 12:25 am

Sweet! It does work on the index! Thank you for the code! :o)

Jonathan
Comment » February 9, 2007 @ 12:34 am

Hmm. No it doesn’t. At least, not without rewinding the loop in the footer. Oh well, it works on pages and posts. Thanks again!

Flick
Comment » March 6, 2007 @ 7:42 pm

I can confirm that this plugin still works in 2.1.2 :)

Niter
Comment » May 24, 2007 @ 5:30 pm

Thanks for a great plugin! I’m new to WP and blogging in general, so I had to play around with it for a while to get it exactly how I wanted. But I definitely got my pages to display the updated dates. Thanks again!

ravishankar
Comment » August 30, 2007 @ 9:35 am

hi, i run a multiple author blog and i want to display the name of the author who last modified the post. tis can be placed at the end of the article and i want the original author name below the heading to be intact. any trick?

Strangely Perfect
Comment » September 20, 2007 @ 5:04 am

Thanks for the plugin work. It works great on my site. It’s the first time I’ve really had a bit of a twiddle with editing a php file and sticking comments in. It’s kicked off my brain in that area so thanks again.
Rees

misty
Comment » October 22, 2007 @ 6:10 pm

Plugin post_updated() doesn’t work for my new pages:

The “last_updated” works for existing pages since I have added the plugin post_updated(). But the “last_updated” does not show up for the new pages that are created after plugin being added.

This is what I have in the index.php:

by

Does anyone know why and how to fix it? Thanks.

misty
Comment » October 22, 2007 @ 6:38 pm

Oh, I think that I have to use both “posted” as well as “post_updated” to handle the new and existing pages. I thought that post_updated() would handle both scenarios.

Please do share your comments if you know a way that post_updated can handle new and existing pages. thanks.

Jon
Comment » November 12, 2007 @ 3:35 pm

I’m looking for the same thing, an overall “Site Last Updated” display, can you send this code to me also?

Thanks!!!

jon

“Hey there,
I’m trying to work out a way where I can use such a script, but for it to only appear on the main site (the blog default page), but put a universal ‘this site was modified’ rather than a ‘this post was modified’. Is this possible?
Say I updated the main page’s latest post on 3rd March, but I updated another separate page on the blog on the 4th March. How do I get the main page to ignore the ‘post updated’ and print only the latest overall update on *any* page?
I added the script to the page.php, it displays the update for each individual page, but I would like to just have one on the main that takes the date/timestamp from whatever page was last updated. Is that easy to do, can I edit the existing script or do I need a totally different sort?
Hope that makes sense.

Kaf
Comment » March 8, 2006 @ 12:24 am
aketus, it makes perfect sense. But my plugin would not work here, and I don’t know of one offhand that does what you’re looking for.
However, there’s not much involved in getting this info and displaying it, so I’ll email you a bit of code which accomplishes what you’re after.”

Flick
Comment » January 3, 2009 @ 1:25 pm

Still going strong in 2.7. One of those plugins that really does what it says on the tin but is so understated.

Johan Ronström
Comment » August 12, 2009 @ 7:52 am

Hi. Nice plugin! Really does the job, and working fine in 2.8! One feature I’d like is to add who made the most recent change. I have multiple editors and I’d like something like the_author() but the one that made the most recent edit…

BB
Comment » December 13, 2010 @ 12:39 am

Still works in WordPress 3.0.3, too. Great plugin!

 

* Required field (e-mail is not published). Breaks and paragraphs are automatic. HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>