From b142319cd440a240b15e6ab183581b0b7756c198 Mon Sep 17 00:00:00 2001 From: Md Rashed Hossain Date: Fri, 24 Sep 2021 13:04:11 +0600 Subject: [PATCH] Update functions.php We can add post reading time feature --- functions.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/functions.php b/functions.php index 591f30f766..7f7b357a0e 100644 --- a/functions.php +++ b/functions.php @@ -184,3 +184,30 @@ function _s_scripts() { if ( class_exists( 'WooCommerce' ) ) { require get_template_directory() . '/inc/woocommerce.php'; } + +/** + * Add Post Reading time. + */ +function post_read_time() { + +// get the post content +$content = get_post_field( 'post_content', $post->ID ); + +// count the words +$word_count = str_word_count( strip_tags( $content ) ); + +// reading time itself +$readingtime = ceil($word_count / 200); + +if ($readingtime == 1) { + $timer = " minute read"; +} else { + $timer = " minute read"; // or your version :) I use the same wordings for 1 minute of reading or more +} + +// I'm going to print 'X minute read' above my post +$totalreadingtime = $readingtime . $timer; +echo $totalreadingtime; +return $totalreadingtime; + +}