---
title: "Display Estimated Reading Time in Joomla Articles - Code Snippets"
description: "Long articles scare readers away when they can't tell how much of their time the page will cost. A small \"6 min read\" line under the title sets that e"
url: "https://www.tassos.gr/docs/code-snippets/howto/content-enhancement/display-article-reading-time"
date: "2026-08-24T00:58:23+00:00"
language: "en-GB"
---

[ Home ](https://www.tassos.gr/index.php?option=com_content&view=category&layout=blog&id=24&Itemid=1088) / [ Code Snippets ](https://www.tassos.gr/index.php?option=com_content&view=category&id=120) / [ How-to Guides ](https://www.tassos.gr/index.php?option=com_content&view=category&id=125) / [ Content Enhancement ](https://www.tassos.gr/index.php?option=com_content&view=category&id=142)

#  Display Estimated Reading Time in Joomla Articles

Long articles scare readers away when they can't tell how much of their time the page will cost. A small "6 min read" line under the title sets that expectation and keeps people scrolling instead of bouncing. Adding an estimated reading time in Joomla normally means installing yet another plugin that you then have to keep updated. You can do it with Code Snippets using a simple PHP snippet.

## [The PHP Snippet Code](#the-php-snippet-code)

Set **Code Type** to `PHP`, then use this snippet. It hooks into Joomla's content preparation, counts the words in the article body, divides them by your configured reading speed, and prepends a short reading time line to the article content. Everything you are meant to change, the reading speed and the wording, sits at the top of the snippet.

 ```
use Joomla\CMS\Factory;

// Average reading speed in words per minute.
$wordsPerMinute = 200;

// Text shown after the number, for example "6 min read".
$label = 'min read';

// Do not edit below.

$app = Factory::getApplication();

$app→registerEvent('onContentPrepare', function ($event) use ($app, $wordsPerMinute, $label)
{
    // Run on the single article view only.
    $input = $app→getInput();

    if ($input→getCmd('option') !== 'com_content' || $input→getCmd('view') !== 'article')
    {
        return;
    }

    $arguments = $event→getArguments();
    $context   = $arguments['context'] ?? $arguments[0] ?? '';
    $article   = $arguments['subject'] ?? $arguments[1] ?? null;

    if ($context !== 'com_content.article' || !is_object($article) || empty($article→text))
    {
        return;
    }

    // Never process the same article twice.
    if (!empty($article→readingTimeAdded))
    {
        return;
    }

    $words   = preg_split('/\s+/u', trim(strip_tags($article→text)), -1, PREG_SPLIT_NO_EMPTY);
    $minutes = max(1, (int) ceil(count($words) / max(1, $wordsPerMinute)));

    $article→readingTimeAdded = true;

    $article→text = '<p class="tcs-reading-time">' . $minutes . ' ' . $label . '</p>' . $article→text;
});
```

The reading time is inserted at the very top of the article body, right below the title in most templates. To style it, add a CSS snippet targeting `.tcs-reading-time`, for example a smaller font size and a muted colour.

## [How to add this snippet](#how-to-add-this-snippet)

1. Install **Code Snippets** if it is not installed already.
2. Go to your Joomla Administrator area.
3. Open **Components** → **Code Snippets**.
4. Click **New**.
5. Select **PHP** as the snippet type.
6. Paste the reading time code above and adjust `$wordsPerMinute` and `$label` to suit your audience.
7. Select **Insertion Method** → **Page Load**.
8. Publish the snippet.
9. Optionally, open the **Conditional Logic** tab to restrict which pages or users the snippet runs on. Leave it empty to run it site-wide. Learn more in [Using Conditional Logic](https://www.tassos.gr/docs/code-snippets/functionality/conditional-logic).

Congrats! You've just added estimated reading time functionality to Joomla without installing another plugin or adding unnecessary bloat to your site.

For instance, to learn more about how the PHP Snippet works, visit our documentation: <https://www.tassos.gr/docs/tassos-code-snippets/types/php>

 Last updated on Aug 17th 2026 12:08
