Skip to main content
FolksSpeakersPluginsThemesEventsSnippetsShippedCommunityResources
Login Join
Snippet · PHP

Add Reading Time Shortcode

Shared by Yusuf mudagal · May 3, 2026 · @add_shortcode

2 views
Back to Snippets

Creates a simple reading-time shortcode based on the current post content and an average 200 words per minute pace.

add_shortcode( 'reading_time', 'wpfolks_reading_time_shortcode' );

function wpfolks_reading_time_shortcode() {
    $word_count = str_word_count( wp_strip_all_tags( get_post_field( 'post_content', get_the_ID() ) ) );
    $minutes    = max( 1, (int) ceil( $word_count / 200 ) );

    return esc_html( sprintf( '%d min read', $minutes ) );
}