Last active
October 17, 2023 00:01
-
-
Save estevan-ulian/5318ab7e871b62f64360184fcdd6396a to your computer and use it in GitHub Desktop.
Cria um shortcode para calcular o tempo de leitura na página do post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_shortcode('reading-time', '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 = " minuto"; | |
} else { | |
$timer = " minutos"; | |
} | |
$totalreadingtime = $readingtime . $timer; | |
ob_start(); | |
?> | |
<span class="reading-time">Tempo de leitura: <?= $totalreadingtime; ?></span> | |
<?php | |
return ob_get_clean(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment