Skip to content

Instantly share code, notes, and snippets.

@rambuvn
Created February 13, 2014 07:40
Show Gist options
  • Save rambuvn/8971301 to your computer and use it in GitHub Desktop.
Save rambuvn/8971301 to your computer and use it in GitHub Desktop.
Estimate Reading Time For Wordpress
/** Estimate Reading Time
*----------------*/
if( !function_exists('rb_timeline_eta') ) {
function rb_timeline_eta(){
global $post;
$words_per_minute = 270;
$words_per_second = $words_per_minute / 60;
$post_content = $post->post_content;
$word_count = str_word_count(strip_tags($post_content));
$total_reading_time = $word_count / $words_per_second;
$reading_time_minutes = round( $total_reading_time / 60 );
$reading_time_seconds = round( $total_reading_time - $reading_time_minutes * 60 );
if( $reading_time_minutes <= 0 ) {
$reading_time_minutes = 1;
}
return sprintf('%d %s %s',
$reading_time_minutes,
__('min','dw-timeline'),
__('read','dw-timeline')
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment