Calculate WordPress Article Reading Time Without a Plugin

You can add estimated reading times to your articles without having to install a plugin using simple PHP.
Written by Justin on September 2, 2022 in
Updated: January 7, 2023 | 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 reading time. I have very little patience and absolutely love when I see the little time snippet before I read anything. If a blog doesn't have a time snippet, you're left to estimate for yourself how long it will take. Some users visit an article with a specific intent of wanting to read something quick or are looking for something more in depth. On top of this, why install an unnecessarily plugin when you can customize everything easily & enable reading time in a single click. Regardless of your technical skills, you have the power to easily 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:

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.

It might even 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. If you use any sort of caching plugin or service, you might to clear your cache for the changes to take effect. Regardless, the snippet should be enabled 'everywhere' for easy access on posts.

adding reading time in wordpress without using a plugin using snippets plugin

Displaying Post Read Time

Once either of these methods are done, you now have to add it somewhere to your post content page. Doing so will call the function which has already been preloaded on any page. Once you call it, it will calculate the words, and return the reading time in paragraph text.

Add Post Reading Time PHP Function

Simply paste the php code by referencing the function name and you should see the time displayed in a format like "4 minutes"

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

Add Post Reading Time with Oxygen Builder

Using Oxygen is a bit easier since you can insert data directly to your post. To do this, go to insert data -> PHP function return value -> gp_reading_time (without the parenthesis). You don't need any function arguments to call it, so leave this blank.

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 an additional plugin. Your users will thank you & your article retention might even improve. Have any questions about reading times in WordPress? Let us know in the comments section below! Happy bloggin'

Join Our Newsletter!
If you enjoyed this article, subscribe to our free monthly newsletter providing you tips & tricks on how to grow your digital business using powerful online tools & AI.
Written by Justin
Justin is the founder of Gold Penguin, a web design and marketing agency that helps businesses increase their revenue using the internet. He writes about the latest software and tools that can help companies 10x their daily workflow & revenue

Comments

Subscribe
Notify of
guest

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