# Reading Time Variable for Rank Math

> Adds a %wpide_reading_time% variable to Rank Math, so titles, descriptions and social text can include an estimated reading time.

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

## Code

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

add_action( 'rank_math/vars/register_extra_replacements', function () use ( $wpide_rm_wpm ) {
    if ( ! function_exists( 'rank_math_register_var_replacement' ) ) {
        return;
    }

    rank_math_register_var_replacement(
        'wpide_reading_time',
        array(
            'name'        => 'Reading time',
            'description' => 'Estimated reading time of the post',
            'variable'    => 'wpide_reading_time',
            'example'     => '4 min read',
        ),
        function () use ( $wpide_rm_wpm ) {
            $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_rm_wpm ) ) ) );
        }
    );
} );
```

## Notes

Type %wpide_reading_time% in any Rank Math title or description field.

## How to use it

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