# Reading Time in Feed Items

> Shows an estimated reading time such as "4 min read" at the start of each item in your feeds, so subscribers know how long an article takes before they open it.

- Type: PHP
- Runs: Run everywhere
- Category: [RSS Feeds](https://wpide.com/library/category/rss/)
- Tags: feeds, reading-time, newsletter
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/reading-time-in-feed-items/

## Code

```php
// Average reading speed in words per minute.
$wpide_feed_wpm = 220;
// Label; %d is replaced by the minutes.
$wpide_feed_reading_label = '%d min read';

$wpide_feed_minutes = function () use ( $wpide_feed_wpm ) {
    static $cache = array();

    $post_id = get_the_ID();

    if ( ! $post_id ) {
        return 0;
    }

    if ( ! isset( $cache[ $post_id ] ) ) {
        $text  = wp_strip_all_tags( strip_shortcodes( (string) get_post_field( 'post_content', $post_id ) ) );
        $words = preg_split( '/\s+/u', trim( $text ), -1, PREG_SPLIT_NO_EMPTY );

        $cache[ $post_id ] = $words ? max( 1, (int) ceil( count( $words ) / max( 1, (int) $wpide_feed_wpm ) ) ) : 0;
    }

    return $cache[ $post_id ];
};

add_filter( 'the_excerpt_rss', function ( $excerpt ) use ( $wpide_feed_minutes, $wpide_feed_reading_label ) {
    $minutes = $wpide_feed_minutes();

    return $minutes ? esc_html( sprintf( $wpide_feed_reading_label, $minutes ) ) . ' · ' . $excerpt : $excerpt;
} );

add_filter( 'the_content_feed', function ( $content ) use ( $wpide_feed_minutes, $wpide_feed_reading_label ) {
    $minutes = $wpide_feed_minutes();

    return $minutes ? '<p><em>' . esc_html( sprintf( $wpide_feed_reading_label, $minutes ) ) . '</em></p>' . $content : $content;
} );
```

## Notes

Change the words-per-minute value to match your audience; shortcodes and HTML are left out of the word count.

## How to use it

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