Created
July 4, 2023 19:44
-
-
Save nfsarmento/b1717a01c3f2bf9f16e6349d74b0cc71 to your computer and use it in GitHub Desktop.
Post estimated reading time shortcode
This file contains hidden or 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 | |
/** | |
* | |
* 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