From 7817f3999aea8f5c65d9943e9440b70fc128d4c5 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 12 Mar 2023 16:26:45 +0100 Subject: [PATCH] feat: ajout temps de lecture Fixes #20 --- components/article.php | 1 + functions.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/components/article.php b/components/article.php index f034e8f..4aef40a 100644 --- a/components/article.php +++ b/components/article.php @@ -6,6 +6,7 @@

+

diff --git a/functions.php b/functions.php index e5c37fc..a8a4a92 100644 --- a/functions.php +++ b/functions.php @@ -322,3 +322,19 @@ register_taxonomy('roman', 'post', ); } add_action( 'init', 'wpb_custom_new_menu' ); + +//estimated reading time +function 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; +} \ No newline at end of file