Using WordPress ‘get_the_modified_date()’ PHP function

The get_the_modified_date() WordPress PHP function retrieves the date on which the post was last modified.

Usage

get_the_modified_date( $format, $post )

Custom Example:

Input:

echo get_the_modified_date('F j, Y', 42);

Output:

May 6, 2023

Parameters

  • $format (string) – Optional. PHP date format. Defaults to the ‘date_format’ option. Default: ''
  • $post (int|WP_Post) – Optional. Post ID or WP_Post object. Default current post. Default: null

More information

See WordPress Developer Resources: get_the_modified_date

Examples

Display the Last Modified Date

Display the last modified date for the current post using the default format.

echo 'Last modified: ' . get_the_modified_date();

Custom Date Format

Display the last modified date for the current post with a custom date format.

echo 'Last modified: ' . get_the_modified_date('F j, Y');

Modified Date for a Specific Post

Display the last modified date for a specific post (e.g., post ID 42) using the default format.

echo 'Last modified: ' . get_the_modified_date('', 42);

Modified Date with Time

Display the last modified date and time for the current post.

echo 'Last modified: ' . get_the_modified_date('F j, Y \a\t g:i a');

Display Modified Date in a Loop

Display the last modified date for each post in a loop using the default format.

if ( have_posts() ) {
    while ( have_posts() ) {
        the_post();
        echo 'Last modified: ' . get_the_modified_date() . '<br>';
    }
}