Post reading time in WordPress without plugin

Welcome to TechSolutionsHere. Today I will show you how to get post reading time in WordPress without plugin. Let’s get started…

Step 1: Please paste the below code into theme functions.php file

//Post reading time
function theme_domain_reading_time() {
    global $post;
    // load the content
    $thecontent = $post->post_content;
    // count the number of words
    $words = str_word_count( strip_tags( $thecontent ) );
    // rounding off and deviding per 200 words per minute
    $m = floor( $words / 200 );

    // calculate the amount of read time
    $readtime = $m . ' min' . ( $m == 1 ? '' : 's' ) ;

    // Result
    $result = '<span>' . $readtime . 'Read'. '</span>';
    // return the readtime
    return $result;
}

Step 2: Call the below function where you want to show

<?php echo theme_domain_reading_time(); ?>

That’s it. Hope this tutorial is helpful for you

Happy Coding! Thanks

Leave a Reply

Your email address will not be published.