Calculate WordPress Article Reading Time Without a Plugin

Published by Justin on September 2, 2022
Last Updated: September 2, 2022 | Reading Time: 5 minutes

If you're a big fan of efficient reading online, you know how frustrating it is when you come across an article that doesn't list its reading time. You're left to estimate for yourself how long it will take, which can often lead to underestimating and not finishing the article at all (especially if you're concerned about wasting your time!). As a WordPress author, you have the power to change this! You can add estimated reading times to your articles without having to install a plugin. Here's how:

Why is Reading Time Important?

Before we get into the mechanics of adding a reading time estimate to your WordPress site, let's talk about why it's important in the first place. There are two main reasons:

1. It helps your readers know what they're getting into

If you want people to read your articles, it's important to give them an idea of what they're getting into before they even start. No one wants to feel like they've been misled or tricked into reading something much longer (or shorter!) than they anticipated.

This is where an estimated reading time comes in handy. By including one at the beginning of your article, you're letting your readers know exactly how long it will take them to get through the piece. No surprises, no wasted time – just good, efficient reading.

2. It can help improve your SEO

In addition to helping your readers, including a reading time estimate can also do wonders for your SEO.

Google has stated that they're interested in user experience when it comes to ranking websites, and one of the key components of a good user experience is – you guessed it – efficient reading! If Google sees that people are spending a lot of time on your site, they're more likely to rank you higher in the search results.

And since an estimated reading time lets people know how long your article will take to read before they even start, they're more likely to stick around until the end (and not click away halfway through). This sends a signal to Google that your content is engaging and worth reading, which can only help your SEO in the long run.

How to Calculate WordPress Article Reading Time Using PHP

If you aren't a fan of plugins or you're just looking for a quick and easy way to add estimated reading times to your WordPress site, you can do it with a few lines of code. There are two ways of adding this: directly into your functions.php file and with a code snippet plugin (assuming you already have this one – so you don't have to install another plugin).

Using functions.php

If you're comfortable editing your theme files, you can add the following code directly to your functions.php file:

function gp_reading_time() {
$article = get_post_field( 'post_content', $post->ID ); //gets full text from article
$wordcount = str_word_count( strip_tags( $article ) ); //removes html tags
$time = ceil($wordcount / 250); //takes rounded of words divided by 250 words per minute
	
if ($time == 1) { //grammar conversion
	$label = " minute";
} else {
	$label = " minutes";
}
	
$totalString = $time . $label; //adds time with minute/minutes label
return $totalString;
	
}

Using Code Snippets Plugin

If you don't feel comfortable editing your theme files, you can use the Code Snippets plugin to add the code. This is a great option if you're not familiar with functions.php or you want to avoid any potential errors that could come from adding code directly to your site. We did promise this tutorial without using a plugin, so this method still fits that guidance assuming you're already using a snippet manager!

To use the Code Snippets plugin, first install and activate it on your WordPress site. Then, go to Snippets > Add New to add a new snippet:

Give your snippet a name and then paste the following code into the content area:

function gp_reading_time() {
$article = get_post_field( 'post_content', $post->ID ); //gets full text from article
$wordcount = str_word_count( strip_tags( $article ) ); //removes html tags
$time = ceil($wordcount / 250); //takes rounded of words divided by 250 words per minute
	
if ($time == 1) { //grammar conversion
	$label = " minute";
} else {
	$label = " minutes";
}
	
$totalString = $time . $label; //adds time with minute/minutes label
return $totalString;
	
}

Click Save Changes and activate the snippet. That's it! You should now see an estimated reading time at the beginning of all your articles.

There are a few things to keep in mind with this method. First, it only works for articles that are hosted on your WordPress site (i.e. posts and pages). Second, if you use any sort of caching plugin or service, you'll need to clear your cache for the changes to take effect.

Displaying Post Read Time

Once either of these methods are done, you now have to add it somewhere to your post content page. Here's how:

With Any WordPress Theme or Builder

You could simply paste the php code by referencing the function name:

<p><?php gp_reading_time(); ?></p>

Specifically Using Oxygen Builder

Using Oxygen is a bit easier since you can insert data to your post. To do this, go to insert data -> PHP function return value -> gp_reading_time (as function name)

custom php using insert data in oxygen builder

Conclusion

And that's all there is to it! With just a few lines of code, you can add estimated reading times to your WordPress articles without having to install a plugin (or additional ones). Trust us, your users will thank you & your article retention should generally be improved. Have any questions or thoughts about adding estimated reading times to WordPress? Let us know in the comments section below!

Written by Justin
Justin is the founder of Gold Penguin, a web design and marketing agency that helps businesses achieve their online goals. Justin has a passion for web design and marketing, and he loves working with clients to help them grow their businesses.

Comments

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
Made with 💛 by Gold Penguin © 2022