Automatic Table of Contents generator for Joomla

Generating a clean, functional table of contents in Joomla has historically been more painful than it should be. After a previous plugin let me down one too many times, I went looking for something better — and found a solution that works reliably in Joomla 5 and Joomla 6. It took a little customisation, but the end result is exactly what I wanted: a compact, styled Bootstrap card sitting neatly above the article content.

TL:DR – Credit to Clifford E Ford, who wrote the original example plugin and documented it on the Joomla developer docs site.

 

A Table of Contents content plugin for Joomla

Clifford E Ford wrote up a detailed walkthrough for building a Table of Contents plugin as a developer tutorial, originally targeting Joomla 4. The good news for anyone running a current Joomla installation is that the plugin installs and runs without issues on both Joomla 5 and Joomla 6. It was never intended as a polished production package, but in practice it is stable and straightforward to adapt.

The plugin works by scanning article content for heading tags and using a

placeholder to determine where the generated list should appear. Drop the placeholder into any article, enable the plugin, and the table of contents builds itself automatically from whatever headings are present in that content.

The plugin code and an installable zip file are available on GitHub: https://github.com/ceford/j4xdemos-plg-toc

Not intended as a production plugin — created for Joomla developer demonstration and tutorial purposes.

That caveat is worth keeping in mind, but it is also worth keeping in perspective. The plugin is written entirely in PHP, licensed under GPL3, and the source is short enough to read and understand in a single sitting. If something breaks after a Joomla update, you can fix it yourself — which is more than can be said for many closed-source alternatives.

Installing

Download the zip file (plg_j4xdemos_toc.zip) directly from the GitHub repository and install it through the standard Joomla Extension Manager. No special steps are required. Once installed and enabled, insert

into the body of any article at the point where you want the table of contents to appear, and the plugin handles the rest.

Customising the output

The default output is functional but minimal. I spent around fifteen minutes editing the PHP to replace the plain output with a Bootstrap card, using card and card-text classes to wrap the generated list. The result fits naturally into a Bootstrap-based Joomla template without any additional CSS — it looks uncluttered and compact, which is exactly what a table of contents should be.

Because the source is so readable, it is also easy to go further. You could filter which heading levels are included, add smooth-scroll behaviour via existing Bootstrap utilities, or adjust the markup to match a custom component library if your template has moved away from vanilla Bootstrap. The plugin gives you a working foundation rather than a black box, which makes it genuinely useful as a starting point even if you end up rewriting large parts of it.

For a site running Joomla 5 or 6 that needs a lightweight, self-hosted table of contents solution without pulling in a third-party extension you cannot audit, this remains one of the cleanest approaches available. It is a small plugin that does one thing, does it transparently, and stays out of the way.