# Reading Time Variable for Yoast Titles and Descriptions

> Adds a %%wpide_reading_time%% variable to Yoast SEO, so meta descriptions or social titles can say "5 min read".

- Type: PHP
- Runs: Run everywhere
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: yoast, variables, reading-time
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/yoast-reading-time-variable/

## Code

```php
// Average reading speed.
$wpide_words_per_minute = 220;

add_action( 'wpseo_register_extra_replacements', function () use ( $wpide_words_per_minute ) {
    if ( ! function_exists( 'wpseo_register_var_replacement' ) ) {
        return;
    }

    wpseo_register_var_replacement( '%%wpide_reading_time%%', function () use ( $wpide_words_per_minute ) {
        $post = get_post();

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

        $words = str_word_count( wp_strip_all_tags( strip_shortcodes( $post->post_content ) ) );

        return sprintf( '%d min read', max( 1, (int) ceil( $words / max( 1, $wpide_words_per_minute ) ) ) );
    }, 'advanced', 'Estimated reading time of the post, for example "5 min read".' );
} );
```

## Notes

Type %%wpide_reading_time%% in any Yoast title or description field. Change the words per minute to suit your readers.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Reading Time Variable for Yoast Titles and Descriptions" 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/
