# Estimated Reading Time Above Posts

> Shows a short "5 min read" line at the top of every blog post, calculated from the number of words in the post.

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

## Code

```php
// Average reading speed in words per minute.
$wpide_words_per_minute = 220;
// Text after the number of minutes.
$wpide_reading_label = 'min read';

add_filter( 'the_content', function ( $content ) use ( $wpide_words_per_minute, $wpide_reading_label ) {
    if ( ! is_singular( 'post' ) || ! in_the_loop() || ! is_main_query() ) {
        return $content;
    }

    $text    = wp_strip_all_tags( strip_shortcodes( get_post_field( 'post_content', get_the_ID() ) ) );
    $words   = count( preg_split( '/\s+/u', trim( $text ), -1, PREG_SPLIT_NO_EMPTY ) );
    $minutes = max( 1, (int) ceil( $words / max( 1, $wpide_words_per_minute ) ) );

    return '<p class="wpide-reading-time" style="opacity:.75;font-size:.9em;">' . esc_html( $minutes . ' ' . $wpide_reading_label ) . '</p>' . $content;
}, 20 );
```

## Notes

Adjust the reading speed in words per minute or the label text at the top of the snippet.

## How to use it

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