feat: ajout temps de lecture

Fixes #20
This commit is contained in:
Kazhnuz 2023-03-12 16:26:45 +01:00
parent bfc18a3cf6
commit 7817f3999a
2 changed files with 17 additions and 0 deletions

View file

@ -6,6 +6,7 @@
<article class="article container-article" id="post-<?php the_ID(); ?>">
<?php if ($haveTitle) { ?>
<h1 class="page-title"><?php the_title(); ?></h1>
<p class="text-right"><span class="btn-small btn-secondary"> <?php echo reading_time(); ?> </span></p>
<?php } ?>
<div class="article-entry">

View file

@ -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;
}