PHP snippet · Content & Text

Reading time shortcode

A shortcode that prints an estimated read time from the post content. Words per minute and the wording after the number are both attributes.

About this php snippet

Drop the shortcode into a post, a template, or any page builder text widget and it prints an estimate such as 4 min read, counted from the post content at the moment the page is built.

200 words per minute is the usual figure for online reading. Raise it for a technical audience who skim, lower it for long form that people actually sit with.

Usage

  • [emcp_reading_time]
  • [emcp_reading_time wpm="240" suffix="minute read"]
  • [emcp_reading_time id="42"] to read a different post

What it does

  • Counts the words in the post content with markup and other shortcodes stripped out first, so a page full of embeds is not counted as reading
  • Rounds up with a floor of one minute, so a short post never reads as zero
  • Falls back to the current post when no id is given, and prints nothing when there is no content to count

Good to know

  • Word counting uses a whitespace split rather than the built-in PHP word counter, which only understands single-byte letters and would badly undercount any language with accents or a non-Latin script
  • Elementor keeps its layout in post meta rather than post content, so on an Elementor page there is usually nothing for it to count. Classic and Gutenberg posts are fully covered.
  • Output is escaped, so it is safe to place anywhere
  • Works in Elementor text widgets, Gutenberg, sidebar widgets, and classic templates

More php snippets

Your EMCP guide

Answers from our docs

YOUR CHAT, YOUR CHOICE

Before we chat

MSR Builds processes your question and up to four recent messages on our server to answer from the EMCP docs. AI is optional and needs your separate permission.

The chat is kept in this page's memory, not saved as a conversation in our database or browser storage. Our hosting and security services process connection information, such as your IP address, to prevent abuse.

Cloudflare Turnstile checks your browser and connection to prevent automated abuse when you send a question. No login is required.

Please leave out personal, sensitive or confidential information, passwords and API keys.

You can withdraw consent and clear this page's chat at any time. This cannot undo a request already sent or erase provider/security records.

Chat privacy, retention & your rights ↗ · Privacy contact

Starting chat consents to this processing. You can browse our docs without using the chat.