i
Table of Contents
i
Harsh Truth

Don't mistake manipulation for affection. It's time to break the chains of a toxic love and breathe in the air of freedom.

Related Posts
Latest Comments
There are 2,380 valuable comments on my blog so far. Many thanks!
  • Kristine Beard: Finding joy and life balance is a lifestyle. It’s hard to [...]
  • Angela Ricardo Bethea: Those are some great points to keep in mind and too much of [...]
  • LisaLisa: I love this post so much. It can be so difficult trying to [...]
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

Loving the wrong person is like planting seeds in poisoned soil. No matter how much you water them, they'll never bloom.

Affiliate
Latest Comments
There are 2,380 valuable comments on my blog so far. Many thanks!
  • Kristine Beard: Finding joy and life balance is a lifestyle. It’s hard to [...]
  • Angela Ricardo Bethea: Those are some great points to keep in mind and too much of [...]
  • LisaLisa: I love this post so much. It can be so difficult trying to [...]
Blog Topics
Harsh Truth

A fake friend's loyalty is as genuine as a mirage in the desert—it vanishes as you get closer.

Related Posts
Latest Comments
There are 2,380 valuable comments on my blog so far. Many thanks!
  • Kristine Beard: Finding joy and life balance is a lifestyle. It’s hard to [...]
  • Angela Ricardo Bethea: Those are some great points to keep in mind and too much of [...]
  • LisaLisa: I love this post so much. It can be so difficult trying to [...]
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 ...

error: content is protected 🎔