Search

Display the Estimated Post Reading Time on WordPress

It seems you’ve come across certain websites that provide the estimated reading time of an article like this one. Personally, when I saw this, I thought it was a bit absurd.

However, I’ve already come across several articles explaining that displaying the estimated reading time increases engagement with the content.

It has been found that users who know the time they need to invest in reading an article tend to read more of the same article, and their time spent on the site increases by about 10%. I refrained from explaining why, but it seems to be simple psychology at work.

It turns out that not long ago, a startup company called monday.com (I built their blog) asked me to embed this option, so I’m even considering adding this functionality to this blog.

Displaying the Estimated Reading Time

If you want to display the estimated reading time in your articles, there is a nice and simple plugin that does the job called Reading Time WP. You can install it and add the functionality automatically using shortcodes, but it does not support translation to Hebrew.

So here’s a simple function I created that displays the estimated reading time in Hebrew. Add this function to your functions.php file of your child theme and call the function wherever you want in your template files.

/**
 * Estimate time to read the article
 *
 * @return string
 */
function savvy_estimated_reading_time() {

	$post = get_post();

    $words = count(preg_split('/\s+/', strip_tags( $post->post_content )));
	$minutes = floor( $words / 200 );
	$seconds = floor( $words % 200 / ( 200 / 60 ) );

	if ( 1 <= $minutes ) {
		$estimated_time = ($minutes == 1 ? ' דקה אחת' : $minutes . 'דקות' ) . ' ו' . ($seconds == 1 ? 'שנייה אחת' :  $seconds . ' שניות' );
	} else {
		$estimated_time = $seconds . ' שניות';
	}

	return $estimated_time;

}
<?php echo savvy_estimated_reading_time(); ?>

Note that we used the php function named strip_tags() to remove html and php tags from the word count calculation.

How is the calculation done?

According to quick studies, an adult’s reading speed is about 250 words per minute. Since I don’t want to display pessimistic reading times, I used a reading speed of 200 words per minute in the function, even though most readers do it faster.

Also, in my opinion, reading time depends on the type of content you are reading. If you need to analyze code or refer to graphs and others, it is clear that the reading time will be longer. Leah Cohen wrote a post on this blog and created a plugin that displays the estimated reading time in posts.

Roee Yossef
Roee Yossef

I develop websites & custom WordPress themes by design. I love typography, colors & everything between, and aim to provide high performance, seo optimized websites with a clean & semantic code.

0 Comments...

Leave a Comment

Up!
Blog