Read time without the plugin

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

Click to Copy