Read time without the plugin

Marko Krstić
23 Jul 2022

According to Medium, people read about 200 words per minute. Medium also adds 12 seconds for each inline image, but I didn’t get that fancy.

Use Scripts Organizer to add this code. Set it as “Everywhere” since that is same as functions.php

<?php

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


?>

After you register a function call it in code block

<p>Read time: <?php echo reading_time(); ?></p>

Result

Article found on medium. Read original article here

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy