This plugin automatically inserts a table of contents (ToC) on every post just before the post content. The ToC will include every h2
, h3
, and h4
heading. The plugin uses the details
and summary
HTML tags to ensure that the ToC is both fully accessible and collapsible without requiring any JavaScript.
Shortcode
The plugin also provides an optional [kts_toc] shortcode that is designed to be placed inside a custom HTML widget, which can then be named manually (e.g. Table of Contents). In this case, the details
and summary
HTML tags are replaced by nav
tags to maintain accessibility, and the ToC will not be collapsible. This widget relies on some JavaScript, but it is so tiny (less than 150 bytes) that it will have no discernible effect on your page loading time.
Configuration
The plugin adds a metabox, headed Table of Contents, on the post edit screen. Checking the box marked “Do not display” and then hitting Update will ensure that no ToC appears on that page.
It is also possible to hide the ToC using CSS, like this: #toc-container { display: none; }
Download
Download Table of Contents
Support
I plan to add a settings page at some point to enable greater flexibility in the plugin’s usage. If you have any issues to report or features to request, please contact me via the Plugin Support Forum, or you can log an issue on the Github repo.