Get most recent update time in WordPress

This simple function will return the date and time of the last update to your WordPress website.

Paste this code in the functions.php file for your theme:

function get_last_update_date($format = 'r') {
    global $wpdb;
    $timestamp = $wpdb->get_var( "SELECT post_modified FROM $wpdb->posts ORDER BY post_modified DESC LIMIT 1" );
    return date($format, strtotime( $timestamp ));
}

 

Call the function with whatever date format you want, and voila!

fold-left fold-right
About the author

Shawn Wernig is a web designer and developer, working primarily with Wordpress based websites. His company, Eggplant Studios is a small studio serving big clients in British Columbia, Canada.

2 Replies to Get most recent update time in WordPress

  1. HI! Wouldn’t it be faster/less memory dependent if you put a LIMIT 1 in the query?

    • Shawn Wernig says:

      Yes, that’s a good suggestion. Even if you’re only looking for a single result, adding LIMIT 1 can make a big impact – I’ll update the post!

Leave a Reply