Add Calculate Reading Time to WordPress site
Add Calculate Reading Time to WordPress site
in

Add Calculate Reading Time to WordPress site in 2020

On an average, We Can Read 200 to 300 Words Per Minute.

You May also Like these:

For people read about 200 words per minute.

// Calculate Reading Time

function epcl_reading_time( $content ) {

// Predefined words-per-minute rate.
$words_per_minute = 225;
$words_per_second = $words_per_minute / 60;

// Count the words in the content.
$word_count = str_word_count( strip_tags( $content ) );

// [UNUSED] How many minutes?
$minutes = floor( $word_count / $words_per_minute );

// [UNUSED] How many seconds (remainder)?
$seconds_remainder = floor( $word_count % $words_per_minute / $words_per_second );

// How many seconds (total)?
$seconds_total = floor( $word_count / $words_per_second );

if( $minutes < 1){
$minutes = 1;
}

return $minutes;
}

OR use this:

For people read about 200 words per minute.

// Calculate Reading Time

function epcl_reading_time( $content ) {

// Predefined words-per-minute rate.
$words_per_minute = 225;
$words_per_second = $words_per_minute / 60;

// Count the words in the content.
$word_count = str_word_count( strip_tags( $content ) );

// [UNUSED] How many minutes?
$minutes = floor( $word_count / $words_per_minute );

// [UNUSED] How many seconds (remainder)?
$seconds_remainder = floor( $word_count % $words_per_minute / $words_per_second );

// How many seconds (total)?
$seconds_total = floor( $word_count / $words_per_second );

if( $minutes < 1){
$minutes = 1;
}

return $minutes;
}

Then you need to call this function to display on your site, and you can put it anywhere, use something like this:

<?php echo reading_time(); ?>

You may also like these:

This returns just a number, so you’ll have to add any context around it in your HTML to put it in context.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading…

0

What do you think?

How to clean malware from website

How to clean malware from the website?

Add a button to the WordPress header

Add a button to the WordPress header