Estimated Reading Time

As more and more websites us article excerpts with a link to full articles, it is important to use all the tools at your disposal to get users to make that valuable click. I’ve noticed on some sites the curators have included an estimated reading time which—without having to clickthrough—let’s the visitor know how much of their time reading the article might take.

So how do we implement this on a wordpress blog?

The short answer. Copy the following to you functions.php file.

function reading_time() {
$mycontent = get_post(get_the_id())->post_content;
$wordcount = round(str_word_count(strip_tags($mycontent)), -2);
$upper = round(($wordcount / 250), 0);
$lower = round(($wordcount / 180), 0);

if ($wordcount $output = __(“Estimated reading time: less than 2 mins”);
} else {
$output = sprintf(__(“Estimated reading time: %s – %s mins”), $upper, $lower);
}
if ($return) {
return $output;
} else {
echo $output;
}
}

to use this in a post or index of posts simply invoke the function like so.

if (function_exists('reading_time')) {reading_time(); }

Were simply taking the number of words in the post and dividing it by the average reading words per minute(180-250wpm).

Leave a Reply