WordPress PHP Free

Show Estimated Reading Time on WordPress Posts

Add an “X min read” badge to your WordPress posts — it counts words at 200 words per minute, with no plugin needed.

16 lines · Updated Nov 26, 2026

Preview of Show Estimated Reading Time on WordPress Posts
wordpress-reading-time-for-posts.php
<?php
function penducoder_reading_time() {
    $words = str_word_count( wp_strip_all_tags( get_the_content() ) );
    $minutes = (int) ceil( $words / 200 );
    return $minutes < 1 ? 1 : $minutes;
}
add_filter( 'the_content', function ( $content ) {
    if ( ! is_single() || ! in_the_loop() || ! is_main_query() ) {
        return $content;
    }
    $badge = sprintf(
        '<p class="reading-time">%s min read</p>',
        esc_html( penducoder_reading_time() )
    );
    return $badge . $content;
} );

About this snippet

A small "5 min read" label at the top of a post tells readers what they are committing to before they start. It is a proven way to reduce bounce on long tutorials, and most themes do not include it. This snippet calculates the estimated reading time from the post's word count and displays it automatically — no plugin, no database changes.

How it works

  1. It takes the post content and strips HTML tags and shortcodes so only readable words are counted.
  2. It divides the word count by an average reading speed (around 200 words per minute) and rounds up, with a minimum of one minute.
  3. It returns a ready-to-display label that you can print in your template or add above the content.

How to use it

  • Add the code to a child theme's functions.php or a small custom plugin, so theme updates do not remove it.
  • Display the label wherever it fits your design — typically next to the author and date.
  • Style it with a simple CSS class to match your theme.

Customize it

  • Technical tutorials with code are read more slowly — try 150–180 words per minute.
  • Change the wording to your language, for example "5 منٹ" for Urdu sites, using translation functions.

Common problems

  • Wrong count for Urdu, Arabic or Hindi: PHP's str_word_count() only counts Latin letters. Split on whitespace with preg_split('/\s+/u', $text) instead.
  • Label appears in sidebars or excerpts: only output it on single post views inside the main loop.

FAQ

Does reading time help SEO? Not directly, but clearer expectations can improve engagement, which is good for readers and for your site.

Related: Reading-progress bar without a plugin · 5 code snippets every developer needs

How to install

Add it to your child theme's functions.php or the Code Snippets plugin. It only runs on single post pages (is_single()), inside the main loop, so your homepage and archive pages are untouched. Style the badge by adding CSS for the .reading-time class in Appearance → Customize → Additional CSS, for example .reading-time { color: #666; font-size: 0.9em; }.

Share this snippet

See all
Chat with us