function prefix_estimated_reading_time($lesson_id) {
$content_post = get_post($lesson_id);
// get the content
$ the_content = $content_post->post_content;
// count the number of words
$words = str_word_count( strip_tags( $the_content ) );
// rounding off and deviding per 200 words per minute
$minute = floor( $words / 200 );
// rounding off to get the seconds
$second = floor( $words % 200 / ( 200 / 60 ) );
// calculate the amount of time needed to read
$estimate = $minute . ' minute' . ( $minute == 1 ? '' : 's' ) . ', ' . $second . ' second' . ( $second == 1 ? '' : 's' );
// create output
$output = '<p>Estimated reading time: ' . $estimate . '</p>';
// return the estimate
return $output;
}
To Run Function Use:
$get_time = prefix_estimated_reading_time($lesson_id);
Jagdish Sarma Asked question November 16, 2021