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.

 

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

 

  1. 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";

				
			

Check these related posts

Optimize Your WordPress Media Settings

Have you ever uploaded an image to your WordPress site, only to find out later that multiple versions of that image were created, cluttering…

How to Restore Lost Functionality After the Latest ACF Update

So, you’re cruising along, happily using Advanced Custom Fields (ACF) to spruce up your WordPress site with custom fields for testimonials, quotes, and all…

How to Apply Bulk Discounts in WooCommerce with a Simple Code Snippet

Ever find yourself wishing that WooCommerce had an easy way to apply bulk discounts based on the number of items in your cart? Maybe…