Created
January 6, 2014 12:12
-
-
Save remkus/8281964 to your computer and use it in GitHub Desktop.
Estimated Reading Time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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