Created
February 28, 2017 00:44
-
-
Save chuckreynolds/5c60037f8fd96a60b224ca36d25a4647 to your computer and use it in GitHub Desktop.
quick wordpress function to get estimated reading time of a post. creator https://www.binarymoon.co.uk/2013/10/wordpress-estimated-reading-time/
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 time required to read the article | |
* | |
* @return string | |
*/ | |
function bm_estimated_reading_time() { | |
$post = get_post(); | |
$words = str_word_count( strip_tags( $post->post_content ) ); | |
$minutes = floor( $words / 120 ); | |
$seconds = floor( $words % 120 / ( 120 / 60 ) ); | |
if ( 1 < = $minutes ) { | |
$estimated_time = $minutes . ' minute' . ($minutes == 1 ? '' : 's') . ', ' . $seconds . ' second' . ($seconds == 1 ? '' : 's'); | |
} else { | |
$estimated_time = $seconds . ' second' . ($seconds == 1 ? '' : 's'); | |
} | |
return $estimated_time; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this code doesn't Arabic language , is there any way to support it ?