Skip to content

Instantly share code, notes, and snippets.

@cre8tivediva

cre8tivediva/functions.php Secret

Last active Oct 21, 2020
Embed
What would you like to do?
How to Add Reading Time to Genesis Child Theme Without a Plugin
/**
* 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() {
$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
You can’t perform that action at this time.