-
-
Save cre8tivediva/c000d15f39f0d87353da345fc8ca6f86 to your computer and use it in GitHub Desktop.
How to Add Reading Time to Genesis Child Theme Without a Plugin
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
/** | |
* Estimated Reading Time | |
* | |
* Code Modified from Original Code Author: | |
* https://medium.com/@nadeem4uwebtech/how-to-add-reading-time-in-wordpress-without-using-plugin-d2e8af7b1239 | |
*/ | |
function c8d_reading_time() { | |
global $post; // Declare global $post to access it within the function | |
$content = get_post_field( 'post_content', $post->ID ); | |
$word_count = str_word_count( strip_tags( $content ) ); | |
$readingtime = ceil($word_count / 200); | |
if ($readingtime == 1) { | |
$timer = " minute"; | |
} else { | |
$timer = " minutes"; | |
} | |
$totalreadingtime = $readingtime . $timer; | |
return $totalreadingtime; | |
} | |
add_shortcode('reading_time', 'c8d_reading_time'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment