i
Table of Contents
i
Harsh Truth

Don't be fooled by the superficial laughter of fake friends; their masks hide their true intentions.

Related Posts
Latest Comments
There are 2234 valuable comments in my blog so far. Many Thanks!
  • Jupiter: Oh wow it's really cool that you've created such a useful plugin!
  • Lavanda Michelle: This is such an awesome idea and cool addition to your blog page. I am...
  • Ben: You should start selling your plugins. I see so many of them on here that...
i
Sponsored Link
Topics

Loading

Display Reading Time on WordPress Blog Without a Plugin

If you are a blogger like me, it is likely that you use WordPress as your platform and you probably want visitors to stick around as long as possible. One way to do this is by providing an estimated reading time for your articles. You might have noticed that some sites do this, with some articles taking as little as one minute to read and others taking much longer.

From what I’ve found in my research, using an estimated reading time can help keep visitors engaged and on your site longer. And if you’re running a WordPress blog, you might be wondering how you can add this feature to your site.

Now, there are plenty of plugins you can use to accomplish this, but I prefer to do things myself whenever possible. And it’s actually not too difficult to add this feature to your site. Essentially all you need to do is take each post, strip out any code tags and unnecessary text and get a word count. Then, you divide that number by 200 (which is a pretty average reading speed) and round up to the nearest whole number. And that’s it!

Of course, you can always adjust the number of words per minute to suit your needs or try different methods of estimating reading time. But this is a good starting point to keep your visitors reading your posts without clicking away. It’s like giving them a heads up!

WordPress Reading Time PHP Code

As mentioned, the average person can read around 200 words per minute. But, if you add in some inline images, it’s a good idea to give an extra 12 seconds for people to take it all in. I didn’t get too fancy with it, but it’s something to keep in mind. You can add this code in your theme’s functions.php file:

function reading_time() {
$content = get_post_field( 'post_content', $post->ID );
$word_count = str_word_count( strip_tags( $content ) );
$readingtime = ceil($word_count / 200);

if ($readingtime == 1) {
$timer = " minute";
} else {
$timer = " minutes";
}
$totalreadingtime = $readingtime . $timer;

return $totalreadingtime;
}

How To Display the PHP Code

To display the function on your site, you can call it and place it anywhere using code:

php echo reading_time(); >

This shows just a number and you may need to tweak it to your specific needs just like what I did. I will be placing a link on the comment section where you can copy/paste it the codes.

How to Display Reading Time on WordPress Blog Without a Plugin

I hope this will enhance the aesthetic and functionality of your blog, because it sure did for me. If you found this post informative and beneficial, please consider sharing it with other bloggers.

September 2023 brief update

I have recently made some changes to the link in the comment section. You can now effortlessly copy and paste both the PHP code and the display code with the fresh link. Why the change, you wonder? Well, the trusty code plugin was misbehaving and just in case it happens again the code is readily available. Plus, that old link had its expiry date. But guess what? I’ve fixed it up, and it’s smooth sailing now!

Facebook
Twitter
Pinterest
WhatsApp
Tumblr
Email
Subscribe
Notify of
guest

32 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Harsh Truth

Don't expect loyalty from fake friends; their allegiance is as unstable as shifting sand.

Affiliate
Latest Comments
There are 2,474 valuable comments on my blog so far. Many thanks!
  • Jupiter: Oh wow it's really cool that you've created such a useful [...]
  • Kat: It’s a challenge, but it’s something I love doing. [...]
  • Kat: You're right! It works great for personal use right now, [...]
Blog Topics
Harsh Truth

Wake up from the nightmare of loving the wrong person, or you'll find yourself starring in your own horror story.

Related Posts
Latest Comments
There are 2,474 valuable comments on my blog so far. Many thanks!
  • Jupiter: Oh wow it's really cool that you've created such a useful [...]
  • Kat: It’s a challenge, but it’s something I love doing. [...]
  • Kat: You're right! It works great for personal use right now, [...]
Affiliate
Topics

Loading

« PREV

Toxic Positivity: The Dark Side of Forced Happiness

Toxic Positivity: The Dark Side of Forced Happiness · Kat&BeyondThe phrase "just be positive" is something that many of us have likely come across ...

NEXT »

Ruined Project: The Café That Almost Wasn’t

Ruined Project: The Café That Almost Wasn't · Kat&BeyondIf you're a fan of unique interiors and delicious coffee, the Ruined Project in Tagaytay ...