How to Automatically Add Reading Time to Your WordPress Posts

Ever wondered how long it would take your readers to finish your blog posts? Adding a reading time estimate can be a great way to set expectations and encourage engagement. And guess what? You don’t need to calculate it manually—there’s a simple way to do it automatically with a free code snippet!

 

Why Reading Time Matters

In the fast-paced world of the internet, attention spans are short. Knowing the estimated reading time can make your content more approachable. It gives your readers a heads-up on how much time they need to invest, helping them decide whether to dive in now or save it for later.

 

The Simple Code Snippet Solution

Thanks to a nifty code snippet shared by Luther Har (shoutout to Luther!), you can automatically calculate and display the reading time for each post on your WordPress site. This is especially useful if you have a large number of posts—it saves you the hassle of manually entering reading times for each one.

 

Here’s how to set it up:

 

  1. Install the Code Snippets Plugin: First, make sure you have the Code Snippets plugin installed on your WordPress site. It’s a versatile tool that lets you safely add custom code without touching your theme files.

 

  1. Add the Reading Time Snippet:

  • Go to the Code Snippets section in your WordPress dashboard.

  • Click Add New to create a new snippet.

  • Give your snippet a title like “Reading Time Calculation.”

 

Paste the following code:

 

php

Copy code

function reading_time() {

    $post_content = get_post_field(‘post_content’, $post);

    $word_count = str_word_count(strip_tags($post_content));

    $minutes = ceil($word_count / 200);

    return $minutes;

}

 

This code calculates the reading time based on an average reading speed of 200 words per minute. Feel free to adjust the words-per-minute value if you think your audience reads faster or slower.

 

3. Activate the Snippet: Save your snippet and activate it. Now, you have a function that automatically calculates reading time for any post.

 

4. Display the Reading Time on Your Posts:

 

You can add the following shortcode anywhere in your post template to display the reading time:

 

php

Copy code

echo “Read Time: ” . reading_time() . ” minutes”;

If you’re using a page builder like Elementor, simply insert the shortcode in a text block where you want the reading time to appear.

 

Final Thoughts

Adding reading time to your posts is a small but powerful way to enhance user experience. It’s like adding a “time budget” for your readers, making your content more accessible and less intimidating. With just a simple snippet, you can automate this process and keep your site running smoothly.

 

Ready to give your readers a better experience? Implement the reading time snippet today, and make your content even more reader-friendly. Got questions or tips? Drop a comment below—we’d love to hear from you!

				
					function reading_time() {
    $post_content = get_post_field('post_content', $post);
    $word_count = str_word_count(strip_tags($post_content));
    $minutes = ceil($word_count / 200);
    return $minutes;
}

				
			
				
					echo "Read Time: " . reading_time() . " minutes";

				
			

Related Articles you may find interesting

Code snippet no longer require child themes

Thank you!

1 million

Active installs of the Code Snippets Plugin! 🎊

Days
Hours
Minutes
Seconds

To celebrate this milestone, we’re launching an exclusive, once-in-a-million-years offer that will be available for the next 1 million seconds (12 days). Use the following code: