Skip to content

Instantly share code, notes, and snippets.

@remkus
Created January 6, 2014 12:12
Show Gist options
  • Save remkus/8281964 to your computer and use it in GitHub Desktop.
Save remkus/8281964 to your computer and use it in GitHub Desktop.
Estimated Reading Time
<?php
/**
* Estimated Reading Time
*
* Use by adding it to a hook like add_action( 'genesis_after_entry', 'fm_estimated_reading_time' );
*
* @link http://briancray.com/posts/estimated-reading-time-web-design/
* @return void
*/
function fm_estimated_reading_time() {
// load the content
$thecontent = $post->post_content;
// count the number of words
$words = str_word_count( strip_tags( $thecontent ) );
// rounding off and deviding per 200 words per minute
$m = floor( $words / 200 );
// rounding off to get the seconds
$s = floor( $words % 200 / ( 200 / 60 ) );
// calculate the amount of time needed to read
$estimate = $m . ' minute' . ( $m == 1 ? '' : 's' ) . ', ' . $s . ' second' . ( $s == 1 ? '' : 's' );
// create output
$output = '<p>Estimated reading time: ' . $estimate . '</p>';
// return the estimate
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment