Skip to content

Instantly share code, notes, and snippets.

@shizhua
Created August 24, 2015 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shizhua/346e0bb98d5708ed9e1d to your computer and use it in GitHub Desktop.
Save shizhua/346e0bb98d5708ed9e1d to your computer and use it in GitHub Desktop.
<?php if( function_exists( 'pt_time_to_read' ) ) { echo pt_time_to_read( 'Time to read: ', ' Minutes' ); } ?>
/** Estimate the time to read the full post **/
function pt_time_to_read( $before = '', $after = '' ) {
global $post;
$count = pt_post_word_content();
$time = $count / 60; // assume 60 words per minute
return $before . round( $time ) . $after;
}
/** Get word count of a post **/
function pt_post_word_content() {
global $post;
//Variable: Additional characters which will be considered as a 'word'
$char_list = ''; /** MODIFY IF YOU LIKE. Add characters inside the single quotes. **/
//$char_list = '0123456789'; /** If you want to count numbers as 'words' **/
//$char_list = '&@'; /** If you want count certain symbols as 'words' **/
return str_word_count(strip_tags($post->post_content), 0, $char_list);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment