WordPress Shortcode to get Estimated Reading Time

Here’s a shortcode to get the estimated reading time of a post/page in WordPress.

Shortcode: [post-read-time]

Code for the shortcode:

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 = " min read";
} else {
$timer = " mins read";
}
$totalreadingtime = $readingtime . $timer;
return $totalreadingtime;
 
}

add_shortcode( 'post-read-time', 'vish_post_read_time_shortcode' );
function vish_post_read_time_shortcode() {
    return reading_time();
}
PHP

Wherever you want to display the total images at site level, you can simply use the [post-read-time] shortcode.

How to add this code to your WordPress site

Leave a Comment