Skip to content

Instantly share code, notes, and snippets.

@estevan-ulian
Last active October 17, 2023 00:01
Show Gist options
  • Save estevan-ulian/5318ab7e871b62f64360184fcdd6396a to your computer and use it in GitHub Desktop.
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
<?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