Skip to content

Instantly share code, notes, and snippets.

@cre8tivediva
Last active April 23, 2024 21:28
Show Gist options
  • Save cre8tivediva/c000d15f39f0d87353da345fc8ca6f86 to your computer and use it in GitHub Desktop.
Save cre8tivediva/c000d15f39f0d87353da345fc8ca6f86 to your computer and use it in GitHub Desktop.
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() {
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