WordPress – Estimated Reading Time

I have a theme coming out soon that displays the ‘estimated reading time’ for each blog post on the homepage.

The theme is inspired by the new blogging service Medium – but I first saw the idea mentioned on Brian Crays blog. I thought it was a really nice thing to add – and the idea that people are more likely to read an article when they know how long it is was quite appealing (in fact I am now wondering if I should add it on this site as well).

Anyway – the code was quite simple – so I turned it into an easily reusable function, as seen below.

All the code does is calculate the number of words in the article, and then assign a number of seconds per word. It’s very simple but gives quite nice results.

/**
 * Estimate time required to read the article
 *
 * @return string
 */
function bm_estimated_reading_time() {

	$post = get_post();

	$words = str_word_count( strip_tags( $post->post_content ) );
	$minutes = floor( $words / 120 );
	$seconds = floor( $words % 120 / ( 120 / 60 ) );

	if ( 1
<p>I'll be posting about the theme in question the future - so I'll point it out then 🙂</p>
<p class="message information">The theme in question is called Kent and it's now available to buy on WordPress.com. You can <a href="http://kentdemo.wordpress.com/">check out the Kent demo here</a>.</p>

How was it for you? Let me know on BlueSky or Mastodon

(Please) Link to this page

Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.

Related Posts

27 Oct 2013

WordPress Numeric Pagination

I’ve made quite a few WordPress themes in my time, and so I thought I would write a few blog posts sharing some of the code snippets that I find myself using repeatedly.First off is some numeric pagination using native...
11 Jul 2014

Localised Estimated Reading Time

So a few people have been writing about my estimated reading time function recently. In particular – it got mentioned on WPTavern in a post all about adding an Estimated Reading Time to your theme.Then I got this tweet: Hey...
26 Sep 2018

WordPress get_post_gallery() Gutenberg Polyfill

I’m working on a new WordPress theme designed for Gutenberg, however Gutenberg isn’t finished, and there are elements that won’t work until the plugin is merged with core.One such issue, that I ran into this weekend, is that get_post_gallery() doesn’t...
06 Apr 2015

Disabling Website URLs in WordPress Comments

These days a lot of spammers submit spam comments that are perfectly legitimate apart from the fact that they link somewhere. So I thought I would disable the website url field in the comments so that comments can focus on...
13 Mar 2018

WordPress: The Difference Between is_home and is_front_page

When making WordPress themes there’s 2 functions that are really handy. is_home and is_front_page. I use them all the time in both themes and plugins. But I can never remember the difference between them.is_home vs is_front_pageOn the surface they are...
01 Dec 2013

WordPress Improved Human Time Difference

WordPress has a built in function, called human_time_diff, for creating messages that say how long ago a post was published – however I think it is confusing when you have posts from a long time ago that read “posted 15...