# Reading Time Shortcode

> Registers a [reading_time] shortcode that shows an estimated reading time such as "4 min read" for the current post.

- Type: PHP
- Runs: Run everywhere
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: content, shortcode, reading-time
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/reading-time-shortcode/

## Code

```php
add_shortcode( 'reading_time', function ( $atts ) {
    $atts = shortcode_atts( array(
        'wpm'   => 220,
        'label' => 'min read',
    ), $atts, 'reading_time' );

    $post = get_post();

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

    $words   = str_word_count( wp_strip_all_tags( strip_shortcodes( $post->post_content ) ) );
    $minutes = max( 1, (int) ceil( $words / max( 1, (int) $atts['wpm'] ) ) );

    return '<span class="reading-time">' . esc_html( $minutes . ' ' . $atts['label'] ) . '</span>';
} );
```

## Notes

Usage: [reading_time] or [reading_time wpm="250" label="minutes"].

## How to use it

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