Skip to main content
Login Join
Snippet · PHP

Automatically Add a Reading Time Estimate to Posts

Shared by Amit Dholiya · August 3, 2026 · @the_content

15 views
Back to Snippets

Show an estimated reading time at the beginning of every blog post based on the content length. This gives readers a quick idea of how long the article will take to read and can improve engagement.

Steps

  1. Open your active theme’s functions.php file or a custom functionality plugin.
  2. Add the code below.
  3. Save the file.
  4. Visit any single blog post to see the reading time displayed above the content.

Benefits

/**
 * Display an estimated reading time before post content.
 */
function wpfolks_add_reading_time( $content ) {

    if ( is_singular( 'post' ) && in_the_loop() && is_main_query() ) {

        $word_count   = str_word_count( wp_strip_all_tags( $content ) );
        $reading_time = max( 1, ceil( $word_count / 200 ) );

        $notice = sprintf(
            '<p class="wpfolks-reading-time"><strong>Reading Time:</strong> %d min read</p>',
            absint( $reading_time )
        );

        $content = $notice . $content;
    }

    return $content;
}
add_filter( 'the_content', 'wpfolks_add_reading_time' );
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments