WordPress • PHP • Intermediate • 10 minutes

Show a Post’s Last Updated Date with a PHP Shortcode

Make a PHP shortcode that shows the current post’s WordPress modified date wherever you place it.

FREE • LAST VERIFIED: SEPTEMBER 28, 2026
The Problem

Show a Post’s Last Updated Date with a PHP Shortcode

A published tutorial can change after its original date. Readers need a visible last-updated date, but the page template may not include one where you want it.

The Fix

Register a small shortcode that retrieves the current singular post’s modified date and returns escaped text. Place [wpbn_updated_date] in the post body or a shortcode-capable builder module.

1

Check the modified date

Open a post or Fix in WordPress and note when it was last updated. The shortcode uses WordPress’s modified date, which changes when the item is edited; it is not a manually verified date.

2

Create the PHP snippet

Go to Snippets → Add New and choose PHP. Give it a clear name, then paste the complete code below. In Code Snippets, do not add another opening <?php tag.

Code Snippets editor with a last updated date shortcode example, before saving.
The PHP example in Code Snippets. This screenshot was taken before saving or activating the snippet.
Copy this PHP
add_shortcode( 'wpbn_updated_date', function () {
    if ( ! is_singular() ) {
        return '';
    }

    $post_id = get_queried_object_id();
    $date    = $post_id ? get_the_modified_date( '', $post_id ) : '';

    if ( ! $date ) {
        return '';
    }

    return '<span class="wpbn-updated-date">Last updated: '
        . esc_html( $date ) . '</span>';
} );
3

Save and activate

Leave the code set to run everywhere, then save and activate the snippet. The callback checks for a single post, page, or custom post type before returning a date.

4

Place the shortcode

Add [wpbn_updated_date] to a post or a Shortcode module in your builder. Save the page, then load it on the front end.

5

Confirm the output

Look for “Last updated:” followed by t