Skip to content

Instantly share code, notes, and snippets.

Last active February 11, 2023 20:57
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
WordPress Estimated Read Time
* Estimates the reading time for a given piece of $content.
* @param string $content Content to calculate read time for.
* @param int $wpm Estimated words per minute of reader.
* @returns int $time Esimated reading time.
function prefix_estimated_reading_time( $content = '', $wpm = 300 ) {
$clean_content = strip_shortcodes( $content );
$clean_content = strip_tags( $clean_content );
$word_count = str_word_count( $clean_content );
$time = ceil( $word_count / $wpm );
return $time;
<div class="reading-time">
<?php echo prefix_estimated_reading_time( get_the_content() ); ?> min read
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment