Automatic Calculate estimated time of reading in Wordpress or PHP in one function & easy way

How to calculate estimate time of reading? Wordpress

Written By: Mohamed Atef

Published: 2021-12-19 | Comments: 1 | Category: Wordpress

Show your visitors the estimated time of reading for each article in your blog in Wordpress or PHP, 
I am going to show you a simple way to calculate the estimated time of reading for each article on your website/blog,
in the function below we gonna calculate 50 words per minute 

function site_estimated_reading_time( $content = '', $wpm = 50 ) { $clean_content = strip_tags( $content ); $word_count = str_word_count( $clean_content ); $time = ceil( $word_count / $wpm ); if($time > 1){ return $time.' Minutes'; }else{ return 'Less than a Minute'; }}

and to calculate it in your custom post type you can pass the content of the post to the function like 

<?php echo "<span class='reading_time'>Estimated reading time: ".site_estimated_reading_time(get_the_content())."</span>"; ?>

and for PHP you can pass any text and it will return it into minutes,
Thank you for reading, if you have any questions please let me know in the comments below




Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

How to create custom Wordpress template?
Publish date: 2021-06-26 | Comments: 0

Tag: Wordpress

How to duplicate or clone Wordpress page ?
Publish date: 2021-04-08 | Comments: 0

Tag: Wordpress

How to protect Wordpress login page?
Publish date: 2021-06-29 | Comments: 0

Tag: Wordpress

One effective way to increase your WordPress website speed
Publish date: 2021-04-02 | Comments: 2

Tag: Wordpress

How to add reCAPTCHA to Wordpress login page?
Publish date: 2021-06-25 | Comments: 0

Tag: Wordpress