Using WordPress ‘get_lastpostmodified()’ PHP function

The get_lastpostmodified() WordPress PHP function retrieves the most recent time that a post on the site was modified.

Usage

get_lastpostmodified( $timezone, $post_type )

Example:

Input:

echo get_lastpostmodified('server', 'post');

Output:

2023-05-08 12:34:56

Parameters

  • $timezone (string, optional) – The timezone for the timestamp. See get_lastpostdate() for information on accepted values. Default is ‘server’.
  • $post_type (string, optional) – The post type to check. Default is ‘any’.

More information

See WordPress Developer Resources: get_lastpostmodified()

Examples

Display the last modified post time in server timezone

This example will display the last modified post time in the server’s timezone.

echo 'Last modified post: ' . get_lastpostmodified();

Display the last modified post time in GMT

This example will display the last modified post time in GMT timezone.

echo 'Last modified post (GMT): ' . get_lastpostmodified('gmt');

Display the last modified page time

This example will display the last modified time for the ‘page’ post type.

echo 'Last modified page: ' . get_lastpostmodified('server', 'page');

Display the last modified custom post type time

This example will display the last modified time for a custom post type called ‘products’.

echo 'Last modified product: ' . get_lastpostmodified('server', 'products');

Display the last modified post time in blog timezone

This example will display the last modified post time in the blog’s timezone.

echo 'Last modified post (Blog Timezone): ' . get_lastpostmodified('blog');