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
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.