Support » Plugins » How to… Last Updated text

  • Hi,
    I was wondering if there was an easy way to get the last update that was made to WordPress.
    I am using WP as a CMS and would like to add a “Site last Updated” tag to the front page (well all pages really)

    Does anyone know of a plugin that does this already or how to work out this information so I can write the plugin myself.



Viewing 8 replies - 1 through 8 (of 8 total)
  • Hey, any chance I’ve sent you an email on this topic?


    If not, and for public consumption, the contents of that email:

    Use this in your templates where you want to display the last update to your blog:

    $last = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts order by post_modified DESC LIMIT 1");
    echo "Last update: " . mysql2date(get_settings('date_format'), $last);

    Description of code:
    $last receives the modified date for the last post or Page on your blog. The echo line displays the modified date, filtered through the WP mysql2date() function (passing it the default date format on your blog).

    If you want to make sure to select only Page updates, use this for your $last code:

    $last = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'static' order by post_modified DESC LIMIT 1");

    You can customize the date/time format by using PHP date format strings:

    echo echo "Last update: " . mysql2date('F j, Y @ g:i a', $last);

    This will output:

    Last update: March 6, 2006 @ 11:09 pm

    Also see:

    No you hadn’t sent that to me by email, but thankyou very much, that’s working a treat

    Just a point I needed to add the global line to the start of the function, but other than that cool, thanks.

    global $wpdb;
    $last = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts order by post_modified DESC LIMIT 1");
    echo "Last update: " . mysql2date(get_settings('date_format'), $last);

    Careful if you copy Kaf’s php date/time example there – there shouldn’t be two ‘echo’s in the code – that gave me errors the first time until I paid more attention and realised what the problem was.

    Damn copy/paste, my constant nemesis…

    Is there a way I could use this code to pull the same information, but for a posts under a particular category? Is there some additional code I could add for example, to limit this function to only look at posts under category ID 6?


    i made up a new template with that code in it so that it would display the last time that page was modified… but it always displays todays date.

    is that because it is in the template and displaying the last time the template was adjusted, or is there something in the code that makes it displays that day’s date?

    $lastpageupdate = $post->post_modified;
    $lastsiteupdate = $wpdb->get_var(“SELECT post_modified FROM $wpdb->posts order by post_modified DESC LIMIT 1”);

    echo “Page last edited on: ” . mysql2date(get_settings(‘date_format’), $lastpageupdate);
    echo ” Site last updated on: ” . mysql2date(get_settings(‘date_format’), $lastsiteupdate);

    This outputs:
    Page last edited on: December 31, 2006 Site last updated on: January 6, 2007

    This worked fine for me in my footer, I didn’t need “global $wpdb;” in line 2 as in some code I have seen, although this may be down to my server config.

    I have been reading around this subject for a while and there are various posts on the subject around this site and the net. This all in-one solution works fine for me in my footer (outside the loop) and I hope it helps a few people out!

    You could always use the post-updated plugin if you dont want to edit your template files, or change them regularly – it’s over at but I wanted more control over the formating of the output without hacking into the plugin.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to… Last Updated text’ is closed to new replies.