Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Reading time shortcode

Type [reading_time] in a post or template to show “4 min read”. [reading_time wpm="180"] changes the reading speed.

  • Type PHP
  • Runs Where you put the [reading_time] shortcode
  • Tested with WordPress 7.1
PHP
<?php

// Change the text to your language: %d is the number of minutes.
$format = '%d min read';

$words_per_minute = max( 50, (int) ( $atts['wpm'] ?? 220 ) );
$text             = wp_strip_all_tags( strip_shortcodes( (string) get_post_field( 'post_content', get_the_ID() ) ) );
$words            = count( preg_split( '/\s+/u', trim( $text ), -1, PREG_SPLIT_NO_EMPTY ) ?: array() );
echo esc_html( sprintf( $format, max( 1, (int) ceil( $words / $words_per_minute ) ) ) );

How to use it

Type [reading_time] in a post, a page or a Shortcode block.

In these packs

  • Content and media: Shortcodes, links, images and small design touches for the public site.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.