Skip to content

Instantly share code, notes, and snippets.

@chuckreynolds
Created February 28, 2017 00:44
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 chuckreynolds/5c60037f8fd96a60b224ca36d25a4647 to your computer and use it in GitHub Desktop.
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/
/**
* 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;
}
@youssifhaliem
Copy link

this code doesn't Arabic language , is there any way to support it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment