DevTeam-Admin
3/26/2020 - 11:05 PM

Estimate reading time on a blog post

This function returns a reading time estimate based ont he number of words in an article

/**
 * Count words in blog articles to estimate reading time
 */
function rs_estimate_reading_time()
{
    global $post;
    $readingContent = str_word_count(strip_tags(get_the_content()));
    $wpm = 200;
    $readingTime = round( $readingContent / $wpm );
    if( $readingTime > 60 ) {
        $readingTime = 'Over an Hour';
    } else {
        $readingTime .= ' minutes'; 
    }
    echo $readingTime;
}