Skip to content

Instantly share code, notes, and snippets.

@nfsarmento
Created July 4, 2023 19: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 nfsarmento/b1717a01c3f2bf9f16e6349d74b0cc71 to your computer and use it in GitHub Desktop.
Save nfsarmento/b1717a01c3f2bf9f16e6349d74b0cc71 to your computer and use it in GitHub Desktop.
Post estimated reading time shortcode
<?php
/**
*
* Post estimated reading time shortcode
*
*/
function ns_reading_time_shortcode() {
$content = get_post_field( 'post_content', $post->ID );
$word_count = str_word_count( strip_tags( $content ) );
$readingtime = ceil($word_count / 200);
if ($readingtime == 3) {
$timer = " min read";
} else {
$timer = " min read";
}
$totalreadingtime = $readingtime . $timer;
return $totalreadingtime;
}
add_shortcode('readingshortcode', 'ns_reading_time_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment