How to add read duration to wordpress posts

Wordpress 4 mins read

How to add read duration to wordpress posts

Last updated: February 5th, 2020

When users visit your blog, they are generally impatient and will most likely leave in a few seconds unless you find a way to convince them to stay.

There are lots of ways to make your blog more attractive to your visitors. You can make it’s content more organized with different categories, use great-looking themes for more attention, and a lot of other things. There’s even a way you can show the estimated reading time of each blog post just below each of the blog post titles or just before the blog post content. This way, your readers know about the length of the blog post before they even go to the details. So, how do we pull this off?

Words Per Minute

The first thing we need to measure the average time our visitors will need to read our posts is the metric, Words Per Minute(WPM), which refers to how many words (on average) an adult can read in a minute. This value can be found in this Free Reading Test:

The average adult reading speed is between 200 and 300 words per minute (same reading rate you want to achieve by the 6th grade). For success in college you should be able to read 350 to 450 words per minute if you want to have any extra time.

– Wikipedia

With this metric and with the count of the number of words in a particular post, we will be able to estimate the reading time of our posts. For instance, if we choose a speed of 200 WPM and our post has 1,000 words approximately, we can estimate that an average adult will take about 5 minutes to read it (1,000 words divided by 200 WPM).

This same calculation is the one used by websites that show the reading time estimation. If you expected something more spectacular than a simple division, I’m sorry to disappoint you.

The Reading Time of Your WordPress Posts

In order to display this information in your WordPress posts, we have several options.

The easiest option is to use a plugin and our recommended plugin is Reading Time WP. Rayhan Arif wrote an excellent article here on installing and customizing Reading Time WP for your blog.

Another option is to add this functionality directly to your theme without plugins. This can be done in 2 ways. In the first method, we attach the reading time to the beginning of the post content. To achieve this, simply copy and paste the code below into your theme’s function file.

/**
 * Estimated Reading Time
 */
function add_reading_time($content) {

	// count the number of words
	$words = str_word_count( strip_tags( $content ) );

	// rounding off and deviding per 200 words per minute
	$m = ceil( $words / 200 );
	
	// create output
	if ($m == 1) {
        $timer = " minute";
    } else {
        $timer = " minutes";
    }

    // return the estimate
    return '<p>Estimated Read Time: ' . $m . $timer . '</p>' . $content;
}

add_filter('the_content', 'add_reading_time', 20, 1);

After adding the code snippet above to your theme’s functions file, you’ll notice that all your posts have a preceding paragraph that shows the estimated read time for the post.

The second method has to do with adding the estimated time whenever and wherever you want within a post. To achieve this, simply add the code snippet below to your theme functions file.

/**
 * Estimated Reading Time
 */
function add_reading_time() {
    global $post;
    $content = get_post_field( 'post_content', $post->ID );

	// count the number of words
	$words = str_word_count( strip_tags( $content ) );

	// rounding off and deviding per 200 words per minute
	$m = ceil( $words / 200 );
	
	// create output
	if ($m == 1) {
        $timer = " minute";
    } else {
        $timer = " minutes";
    }

    // return the estimate
    return $m . $timer ;
}

After that, edit your single post template (it usually will be either single-post.php, single.php or singular.php) and add the code snippet below to any line where you want the estimated time to appear.

<?php add_reading_time(); ?>

Final Thoughts

Although it may seem very interesting to see how long it will take to read the post, it is possible that those who are more lazy/busy think that spending those minutes to read it is not worth it, spending their time doing other tasks and without reading your text.

On the one hand, showing this information can attract more readers and increase the time they spend on your page.

Join the conversation, leave a comment below

This site uses Akismet to reduce spam. Learn how your comment data is processed.