# Block Bindings Source: Formatted Post Dates

> Registers a block bindings source that fills blocks with the post's published or last updated date in any format, so you can write "Updated on ..." in a paragraph inside block templates.

- Type: PHP
- Runs: Run everywhere
- Category: [Block Editor](https://wpide.com/library/category/gutenberg/)
- Tags: block-bindings, dates, block-themes
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/bindings-post-dates/

## Code

```php
add_action( 'init', function () {
    if ( ! function_exists( 'register_block_bindings_source' ) ) {
        return;
    }

    register_block_bindings_source( 'wpide/dates', array(
        'label'              => 'Post dates',
        'uses_context'       => array( 'postId' ),
        'get_value_callback' => function ( $args, $block ) {
            $post = get_post( ! empty( $block->context['postId'] ) ? (int) $block->context['postId'] : get_the_ID() );
            if ( ! $post ) {
                return null;
            }

            $format = isset( $args['format'] ) ? sanitize_text_field( $args['format'] ) : get_option( 'date_format' );

            switch ( $args['key'] ?? 'published' ) {
                case 'modified':
                    return esc_html( get_the_modified_date( $format, $post ) );
                case 'year':
                    return esc_html( get_the_date( 'Y', $post ) );
                default:
                    return esc_html( get_the_date( $format, $post ) );
            }
        },
    ) );
} );
```

## Notes

Needs WordPress 6.5+; bind with "source":"wpide/dates" and args {"key":"modified","format":"F j, Y"} (keys published, modified, year).

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Block Bindings Source: Formatted Post Dates" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
