Automatically calculate and display estimated reading time before post content based on average reading speed. Helps improve user engagement and content readability.
add_filter( 'the_content', 'wpf_add_reading_time' );
function wpf_add_reading_time( $content ) {
if ( ! is_single() ) {
return $content;
}
$word_count = str_word_count( wp_strip_all_tags( $content ) );
$reading_time = ceil( $word_count / 200 );
$label = sprintf(
'<p><strong>Estimated Reading Time:</strong> %d min</p>',
$reading_time
);
return $label . $content;
}