Created
August 24, 2015 13:40
-
-
Save shizhua/346e0bb98d5708ed9e1d to your computer and use it in GitHub Desktop.
This file contains 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 if( function_exists( 'pt_time_to_read' ) ) { echo pt_time_to_read( 'Time to read: ', ' Minutes' ); } ?> |
This file contains 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
/** 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; | |
} |
This file contains 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
/** 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