How to Add a Reading Time Estimate to WordPress Posts Without a Plugin

Every reading time plugin on the repository does the same thing: it counts the words in your post, divides by a reading speed, and prints a line of text. That is roughly twenty lines of PHP. Installing a plugin for it means an extra update to track, extra options pages, extra queries and often an extra stylesheet loaded on every page of your site.

This tutorial shows you how to add WordPress reading time without a plugin: a reusable helper function, a filter-based snippet for functions.php, a version that works in block (Full Site Editing) themes, plus notes on caching, placement and troubleshooting.

Before you paste any code

  • Use a child theme or a site-specific snippet file. Code added to a parent theme’s functions.php disappears on the next theme update.
  • If you prefer not to touch theme files at all, a code snippet manager works too, but the point here is to avoid dependencies, so a child theme is cleaner.
  • Take a backup, or at least keep file access (FTP / SFTP / file manager) open so you can undo a syntax error.
  • All examples use the exjs_ prefix. Change it to your own prefix to avoid function name collisions.
clock and laptop

Step 1: The core function that counts words

This is the only piece of logic you actually need. It pulls the raw post content, strips tags and shortcodes, counts words and returns a number of minutes (never less than 1).

<?php
/**
 * Return the estimated reading time in minutes.
 *
 * @param int|null $post_id Post ID. Defaults to current post.
 * @param int      $wpm     Words per minute.
 * @return int
 */
function exjs_get_reading_time( $post_id = null, $wpm = 200 ) {

    $post_id = $post_id ? $post_id : get_the_ID();

    if ( ! $post_id ) {
        return 1;
    }

    $content = get_post_field( 'post_content', $post_id );
    $content = strip_shortcodes( $content );
    $content = wp_strip_all_tags( $content );

    $words   = preg_split( '/\s+/', trim( $content ), -1, PREG_SPLIT_NO_EMPTY );
    $count   = is_array( $words ) ? count( $words ) : 0;

    $minutes = (int) ceil( $count / max( 1, (int) $wpm ) );

    return max( 1, $minutes );
}

Why get_post_field and not get_the_content()?

Using the raw database content means the count is identical whether you call it inside the loop, in an archive, in a REST response or in a template part. It also avoids counting HTML generated by other filters (related posts, ads, share buttons) that would inflate the estimate.

Step 2: Output it in the post meta area with a filter

The fastest way to display it, with zero template editing, is to hook into the_content and prepend the badge on single posts only.

<?php
function exjs_prepend_reading_time( $content ) {

    if ( ! is_singular( 'post' ) || ! in_the_loop() || ! is_main_query() ) {
        return $content;
    }

    $minutes = exjs_get_reading_time();

    $label = sprintf(
        /* translators: %s: number of minutes */
        _n( '%s min read', '%s min read', $minutes, 'exjs' ),
        number_format_i18n( $minutes )
    );

    $badge = '<p class="exjs-reading-time">' . esc_html( $label ) . '</p>';

    return $badge . $content;
}
add_filter( 'the_content', 'exjs_prepend_reading_time' );

The three conditions matter:

  • is_singular( 'post' ) keeps it off pages, products and custom post types.
  • in_the_loop() prevents it from being injected into excerpts, feeds or page builder previews.
  • is_main_query() stops duplicate output when a theme or block renders post content a second time.

A touch of CSS

.exjs-reading-time {
    display: inline-block;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    opacity: 0.7;
    margin: 0 0 1.25rem;
}

Add it to your child theme stylesheet, or to Appearance > Customize > Additional CSS if you want to stay out of files entirely.

clock and laptop

Step 3: Place it where the theme meta already lives

Prepending to the content is convenient, but it sits below the featured image on most themes. If you want it next to the date and author, call the helper directly in the template.

In a classic theme, open single.php or the template part that prints the entry meta (often template-parts/content.php) and add:

<?php echo esc_html( exjs_get_reading_time() ); ?> min read

Or hook into your theme’s meta action if it exposes one, for example many themes fire something like theme_entry_meta or after_entry_header.

The block theme (FSE) version

Block themes do not have single.php to edit, so you have two clean options.

Option A: a shortcode you can drop in any template

<?php
add_shortcode( 'reading_time', function( $atts ) {

    $atts = shortcode_atts(
        array(
            'wpm'    => 200,
            'suffix' => 'min read',
        ),
        $atts,
        'reading_time'
    );

    $minutes = exjs_get_reading_time( get_the_ID(), (int) $atts['wpm'] );

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

Then in Appearance > Editor, open the Single template, add a Shortcode block inside the post meta row and type [reading_time]. The same shortcode works inside a Query Loop, so your blog index and category archives can show it under each preview.

Option B: block bindings (the modern way)

Block bindings let a normal Paragraph block pull its text from PHP, so the output stays fully themeable in the editor.

<?php
add_action( 'init', function() {

    register_block_bindings_source(
        'exjs/reading-time',
        array(
            'label'              => __( 'Reading time', 'exjs' ),
            'uses_context'       => array( 'postId' ),
            'get_value_callback' => function( $source_args, $block_instance ) {

                $post_id = isset( $block_instance->context['postId'] )
                    ? $block_instance->context['postId']
                    : get_the_ID();

                $minutes = exjs_get_reading_time( $post_id );

                return sprintf( '%d min read', $minutes );
            },
        )
    );
} );

Then edit the template in code view and bind a paragraph to the source:

<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"exjs/reading-time"}}},"className":"exjs-reading-time"} -->
<p class="exjs-reading-time">Reading time</p>
<!-- /wp:paragraph -->

Because the source declares postId context, the same paragraph works inside a Query Loop and resolves per post.

clock and laptop

Choosing a words-per-minute value

Reading speed research for adults on screen generally lands between 200 and 250 words per minute for non technical prose. Slower is safer: an estimate that reads “6 min” for a post people finish in 5 feels generous, the opposite feels like a lie.

Content type Suggested WPM Why
News, lifestyle, opinion 230 – 250 Linear prose, light scanning
Marketing and general blogging 200 – 220 Safe default, matches most plugins
Technical tutorials, docs 140 – 180 Code blocks are re-read, not skimmed

Quick reference with the default 200 WPM:

Word count Displayed estimate
0 – 200 1 min read
600 3 min read
1,200 6 min read
2,400 12 min read

Counting images and code blocks

If your posts are image heavy, add a few seconds per image the way Medium does (12 seconds for the first image, decreasing after). A simple version:

<?php
function exjs_image_seconds( $post_id ) {
    $content = get_post_field( 'post_content', $post_id );
    $images  = substr_count( $content, '<img' ) + substr_count( $content, 'wp:image' );
    return $images * 10;
}

Then add those seconds to $count / $wpm * 60 before rounding up.

Cache the result on busy sites

Counting words on a 3,000 word post is cheap, but doing it for 12 posts in an archive on every uncached request adds up. Store the value in post meta and refresh it on save.

<?php
function exjs_cached_reading_time( $post_id = null ) {

    $post_id = $post_id ? $post_id : get_the_ID();
    $minutes = get_post_meta( $post_id, '_exjs_reading_time', true );

    if ( '' === $minutes ) {
        $minutes = exjs_get_reading_time( $post_id );
        update_post_meta( $post_id, '_exjs_reading_time', $minutes );
    }

    return (int) $minutes;
}

add_action( 'save_post', function( $post_id ) {
    if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
        return;
    }
    delete_post_meta( $post_id, '_exjs_reading_time' );
} );

Use exjs_cached_reading_time() instead of the raw function everywhere once this is in place.

clock and laptop

Where to place the estimate for the best UX

Placement changes behaviour more than the number itself. Readers use it as a commitment signal, so it has to appear before they decide to scroll.

Location Good for Watch out for
Entry meta line (next to date / author) The default best choice, visually expected Needs template or binding edit
Top of the content (filter method) Zero template work, visible above the fold Sits under the featured image on some themes
Archive and blog post cards Improves click decisions, pairs well with excerpts Needs the shortcode or binding inside the Query Loop
Sticky header with progress bar Long form content, documentation Requires JavaScript, can feel heavy on mobile
Bottom of the post Nothing, really The decision has already been made

Three small UX rules worth following:

  1. Keep the wording short and consistent: “6 min read” beats “Estimated reading time: approximately 6 minutes”.
  2. Do not show it on pages like Contact or Pricing. It signals “long article” where no article exists.
  3. Round up, never down. Under-promising on time is the one place where being pessimistic helps.

Hiding it on specific posts or pages

A common request: keep the estimate on single posts but remove it from a given page, category or landing post. Add an early return to the filter.

<?php
// Inside exjs_prepend_reading_time(), before building the badge:
if ( has_category( 'announcements' ) ) {
    return $content;
}

if ( get_post_meta( get_the_ID(), 'hide_reading_time', true ) ) {
    return $content;
}

With the second check, adding a custom field named hide_reading_time with any value to a post removes the badge from that post only.

clock and laptop

Troubleshooting

The estimate does not appear under blog post previews

The the_content filter does not run on excerpts. Archives render the_excerpt() or an Excerpt block, so you need the shortcode or block binding method inside the Query Loop template, or a second filter on get_the_excerpt.

It shows twice

Either your theme or your SEO plugin already prints one. Yoast SEO, for example, offers an estimated reading time block, and several block themes include their own meta. Remove one of the two, and keep is_main_query() in your condition.

The number looks too low

Shortcodes, reusable blocks (synced patterns) and page builder content are not stored as plain text in post_content, so their words are not counted. For page builder sites, count the rendered output instead by replacing get_post_field with apply_filters( 'the_content', ... ), and cache the result as shown above.

Fatal error after saving functions.php

Almost always a duplicated function name or a missing semicolon. Rename the function with your own prefix, or restore the file by FTP. WordPress recovery mode will also email you a login link to fix it.

Snippet vs plugin: the honest comparison

Criteria Custom snippet Reading time plugin
Weight About 20 lines, no extra assets Options page, CSS, sometimes JS
Maintenance None unless you change themes Updates, compatibility, abandonment risk
Control over markup Total Limited to provided options
Non technical editing Requires a developer Settings UI for everyone
Survives theme switch No, unless placed in a small site plugin Yes

If you want the snippet to survive a theme switch, wrap it in a one file site-specific plugin in wp-content/plugins/. You still avoid third party code, and the feature stays active forever.

FAQ

Does reading time help SEO?

Not directly, there is no reading time ranking factor. It helps indirectly by setting expectations, which can improve engagement and reduce immediate bounces on long articles.

What is a good default reading speed?

200 words per minute is the safest default for general blogs. Lower it to 140 – 180 for tutorials packed with code.

Can I show reading time in seconds for short posts?

You can, but it is rarely worth it. A floor of “1 min read” is clearer than “42 sec read” and avoids odd values on short updates.

Will this work with Elementor, Divi or other page builders?

The helper function works, but builder layouts store markup outside the standard content field, so the word count may be too low. Use the rendered content variant described in the troubleshooting section, with caching enabled.

Does it work with custom post types?

Yes. Replace is_singular( 'post' ) with is_singular( array( 'post', 'docs' ) ), or any post types you need.

Can I display reading time in the REST API or the editor sidebar?

Yes. Register the cached value as post meta with show_in_rest => true, then read it from any headless front end or editor plugin without recalculating.

Wrap up

Reading time is the textbook example of a feature that does not justify a plugin. One helper function, one filter, optional caching, and you have full control over wording, markup and placement. Paste the snippet into a child theme or a small site plugin, pick a words-per-minute value that matches your content, and put the badge where readers look before they scroll.

Recent Posts

No Posts Found!

Categories

Tags

    Subscribe

    You have been successfully Subscribed! Ops! Something went wrong, please try again.

    About Us

    Express Jam Studio was founded in 2004 by John Smith. John had previously worked for a courier company, but he saw an opportunity to start his own business in the web design and development industry.

    Contact Info

    Copyright © 2022 Express Jam Studio. All Rights Reserved.