-
-
- Submit Updated Articles to Bing and Yandex with IndexNow in Joomla
- Add Published and Modified Date Meta Tags to Joomla
- Add Open Graph and Twitter Card Tags to Joomla
- Auto-Generate Meta Descriptions from Article Text in Joomla
- Add Noindex to Specific Pages in Joomla
- Verify Your Joomla Site with Google Search Console
-
- Add a View as Markdown Link to Joomla Articles
- Display the Last Modified Date in Joomla Articles
- Embed Iframes in Joomla
- Automatically Link Twitter (X) @mentions in Joomla Articles
- Open External Links in a New Tab in Joomla
- Display Estimated Reading Time in Joomla Articles
- Replace Old URLs in Joomla
- Search and Replace in Joomla
-
- Add a Footer Line to the Joomla Administrator
- Show a Staging Banner in the Joomla Administrator
- Remove the "All" Option from Admin List Limits in Joomla
- Add a Cookie Consent Banner to Joomla
- Make the Administrator Navigation Sticky in Joomla
- Add Google Fonts to Joomla
- Add a Facebook Messenger Chat Button to Joomla
- Add a Reading Progress Bar to Joomla
- Add a Custom Scrollbar to Joomla
- Show Confetti on a Thank You Page in Joomla
- Add Smooth Scrolling to Joomla
- Add a Back to Top Button in Joomla
- Add a WhatsApp Chat Button in Joomla
-
- Protect the Administrator with a Secret URL Key in Joomla
- Show a Welcome Message on First Login in Joomla
- Log Out Idle Administrators in Joomla
- Assign New Users to a Different User Group Automatically in Joomla
- Redirect Visitors by Country in Joomla
- Redirect Users After Login by User Group in Joomla
- Block User Registration with Certain Usernames in Joomla
- Block User Registration by Country in Joomla
- Block User Registration by Email Address in Joomla
- Block User Registration by IP Address in Joomla
- Remove the Forgot Password and Username Links in Joomla
- Remove the Generator Meta Tag in Joomla
- Let Users Log In with Their Email Address in Joomla
- Block Traffic by Country in Joomla
- Block Bot Traffic in Joomla
- Block Traffic by IP Address in Joomla
Display Estimated Reading Time in Joomla Articles
Show an estimated reading time on your Joomla articles so readers know what they're in for and keep scrolling, using one PHP snippet.
Long articles scare readers away when they can't tell how much time the page will cost them. A small "6 min read" line under the title sets that expectation and keeps people scrolling. Showing a reading time in Joomla usually means installing another plugin that you then have to keep updated. You can add it with one PHP snippet in Code Snippets.
The PHP snippet code
When Joomla prepares an article, the snippet counts the words in its body, divides them by your reading speed, and adds a reading time line at the top of the article. It runs on single article pages only, so blog and featured lists stay as they are.
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();
$addReadingTime = 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;
}
$text = trim(strip_tags($article->text));
$words = preg_split('/\s+/u', $text, -1, PREG_SPLIT_NO_EMPTY);
$minutes = max(1, (int) ceil(count($words) / max(1, $wordsPerMinute)));
$article->readingTimeAdded = true;
$badge = '<p class="tcs-reading-time">' . $minutes . ' ' . $label . '</p>';
$article->text = $badge . $article->text;
};
$app->registerEvent('onContentPrepare', $addReadingTime);
Change $wordsPerMinute to match your readers, and $label to change the text after the number. At 200 words per minute, a 1,500-word article shows "8 min read".
In Cassiopeia the line appears right under the article details. To style it, add a CSS snippet that targets .tcs-reading-time, for example with a smaller font and a grey color.
How to add this snippet
- Install Code Snippets if it isn't installed already.
- Log into your Joomla backend.
- Go to Components → Tassos Code Snippets.
- Click New.
- Enter a title, for example Reading time.
- Set Code Type to PHP.
- Set Insertion Method to Auto-Insert Locations.
- Set Location to On Page Load.
- Paste the code above into the editor.
- Click Save & Close.
Check that it works
- Open a long article on your site.
- Look at the top of the article text.
You should see a line like "8 min read". Blog and featured pages don't show it.
To link @mentions in your articles to X profiles, see Automatically Link Twitter (X) @mentions in Joomla Articles. To learn more about how PHP snippets work, read the PHP snippet docs.