Last Updated: September 09, 2019
·
4.513K
· kevinsperrine

Estimate Reading Time

I just came across the idea of estimating the time to read content on a website, so I threw together this https://gist.github.com/3253541 based on this idea.

<?php
/**
 * Returns an estimated reading time in a string
 * idea from @link http://briancray.com/posts/estimated-reading-time-web-design/
 * @param  string $content the content to be read
 * @return string          estimated read time eg. 1 minute, 30 seconds
 */
function estimate_reading_time($content) {
    $word_count = str_word_count(strip_tags($content));

    $minutes = floor($word_count / 200);
    $seconds = floor($word_count % 200 / (200 / 60));

    $str_minutes = ($minutes == 1) ? "minute" : "minutes";
    $str_seconds = ($seconds == 1) ? "second" : "seconds";

    if ($minutes == 0) {
        return "{$seconds} {$str_seconds}";
    }
    else {
        return "{$minutes} {$str_minutes}, {$seconds} {$str_seconds}";
    }
}

1 Response
Add your response

I made a small plugin a while back just for this purpose :)

http://wordpress.org/extend/plugins/post-reading-time/

over 1 year ago ·