# Block Bindings Source: Reading Time

> Registers a "Reading time" block bindings source, so a Paragraph or Heading in your templates can show "5 min read" for the current post (WordPress 6.5+).

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

## Code

```php
// Average reading speed in words per minute.
$wpide_binding_wpm = 220;

add_action( 'init', function () use ( $wpide_binding_wpm ) {
    if ( ! function_exists( 'register_block_bindings_source' ) ) {
        return;
    }

    register_block_bindings_source( 'wpide/reading-time', array(
        'label'              => 'Reading time',
        'uses_context'       => array( 'postId' ),
        'get_value_callback' => function ( $source_args, $block_instance ) use ( $wpide_binding_wpm ) {
            $post_id = isset( $block_instance->context['postId'] ) ? (int) $block_instance->context['postId'] : get_the_ID();
            $words   = str_word_count( wp_strip_all_tags( (string) get_post_field( 'post_content', $post_id ) ) );

            return esc_html( sprintf( '%d min read', max( 1, (int) ceil( $words / max( 1, $wpide_binding_wpm ) ) ) ) );
        },
    ) );
} );
```

## Notes

In the Code editor, add {"metadata":{"bindings":{"content":{"source":"wpide/reading-time"}}}} to a Paragraph block's attributes.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Block Bindings Source: Reading Time" 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/
