Ben
Ben is a lifelong Nintendo fan who likes to build websites, and make video games. He buys way too much Lego.
WordPress and Games
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 I'll be posting about the theme in question the future - so I'll point it out then :)
Simple but effective, I would think. Remember seeing this feature on certain news sites sometime ago but had discontinued. Wonder if there’s a way to get this info on Google search listing info (just like the star buttons). For example, against a search result if it has a 5 star along with a reasonable reading of say 3 minutes, the CTR might just increase.
Any thoughts?
That’s an interesting idea but as far as I know it’s not possible to add to search results unfortunately.
That’s cool, I’ll probably add it to my site, thanks!
Just curious, how did you come up with the 120 words per minute? Is that a standard?
Thanks Jeremy – apparently the average words per minute is 200 – however I felt the numbers seemed too low when I set it there so I played with the figures and 120 felt about right.
For reference the theme is now released on wordpress.com as well – you can check out the Kent Demo here π
Very handy addition to a theme. The need to call get_post() could be eliminated by using the ‘the_content’ filter:
That’s a good option if you want it added at the end of the post data for sure. I like to be able to mix up the location of the text though – so a separate function gives me that flexibility.
Ah yes. In that case that’s an optimum solution
I tried this code and it’s not working anymore. Is there any update to have it work with the latest version of WordPress?
Hi Jesse – that’s strange. It definitely still works. You can see it in action in the theme linked in the article.
Great Post!
Following your post we’ve published a post not too long ago explaining how to create a WordPress plugin which display’s the estimated reading time (In Hebrew only at the moment).
https://he.savvy.co.il/blog/?p=5262
Hope that Hebrew sites owner’s will find it useful… π
Hi thanks for this great tutorial.
put just to ask can your code be used for commercial purpose without any licensing issues?
I would like to use it for a major project, so I opt to ask first.
Regards.
Hi Lawrence – thanks for the message. You’re more than welcome to use the code in your own projects.
Thanks! Ben