Free WordPress plugin · GPL-2.0-or-later

A table of contents that follows you while you read

Auto Floating TOC builds a table of contents from the headings in your post. Once you scroll past it, a floating copy stays with you: a column beside the text on wide screens, or a small button in the corner on smaller ones.

Requires WordPress 6.3 or later and PHP 7.4 or later. Coming soon to the WordPress.org directory.

How it works

Install the plugin, activate it, and open a post with a few headings. When the post has at least three top-level h2 headings (you can change that number), the plugin inserts an “On this page” list just before the first section. There is no shortcode to add and no block to place.

This page uses the plugin’s own stylesheet and script for its table of contents. Scroll down: once this list scrolls away, the floating copy appears on the right on a wide screen, or as a button in the bottom-right corner on a narrow one.

Two copies, one list

The floating copy is a clone of the list in the article. Both copies mark the section you are reading with aria-current and a bold label with a left rule, so the state never depends on colour alone. On a small screen the corner button shows the current heading and opens the full list. Press Escape to close it and the focus returns to the button.

Your saved content stays untouched

The table of contents and any missing heading IDs are added when the post is displayed. Nothing is written back into the database, so you can switch the plugin off without leftover shortcodes or blocks. Existing heading IDs are kept.

Features

  • Automatic. The list is built from h2 headings, and optionally h3 and h4.
  • Floating copy. A column beside the text on wide screens; a corner button when there is no room or another element is in the way.
  • Active section. Scroll highlighting in both copies, with the current item kept in view inside the floating panel.
  • Accessible. A nav landmark, aria-current on the current link, a keyboard-operable toggle and Escape to close. Smooth scrolling only applies when the visitor has not asked for reduced motion.
  • Fits the theme. Works with block themes and classic themes. It hooks into the Post Content block and inherits the theme’s fonts and colours through currentColor.
  • Cleans up duplicates. Optionally hides a hand-written “Table of Contents” heading, a list of in-page links, or a core Table of Contents block when the automatic list is shown.
  • No remote calls. The plugin does not contact third-party services.
  • Free software. Released under the GNU General Public License, version 2 or later.

Try it

The Playground demos start a disposable WordPress site in your browser with the plugin installed and a long sample post open. You are logged in, so you can open Settings → Auto Floating TOC and change the options.

Settings and filters

All options live under Settings → Auto Floating TOC.

SettingDefaultWhat it does
Minimum headings3Show the list only when the content has at least this many h2 headings (1–20).
Heading levelsh2 and h3Include h2 only, h2 and h3, or h2, h3 and h4.
Default titleemptyLeave empty to use the translated default, “On this page”.
Floating copyonShow the floating copy once the in-content list has scrolled away.
Hide hand-written TOCsonHide a “Table of Contents” heading, lists of in-page links, or a core Table of Contents block.
Post typespostPublic post types where the list may appear. Pages and custom types can be enabled.
Disable default CSSoffSkip the plugin stylesheet if your theme provides its own.

Filters for developers

Hooks let a theme or a small companion plugin change behaviour without forking: aftoc_enabled, aftoc_label (for a per-post title or language), aftoc_min_sections, aftoc_max_level, aftoc_entries, aftoc_disable_css, aftoc_removed_blocks and aftoc_float_layout (auto or corner). To restyle, override the --aftoc-* CSS custom properties. Each filter is documented in the README.

FAQ

Does this work with a block theme?

Yes. The list is inserted into the Post Content block on the front end. It does not need the Customizer, widgets or a classic sidebar.

Will it change my saved content?

No. Heading IDs and the list markup are added when the post is displayed. The post in the database is unchanged.

How do I change the title on some posts?

Set a site-wide title under Settings → Auto Floating TOC, or use the aftoc_label filter to return a different string for a given post ID, for example from post meta or a multilingual plugin.

The colours do not match my theme.

The stylesheet uses currentColor and inherited fonts. You can override the --aftoc-* CSS custom properties in your theme, or disable the default CSS in the settings and write your own.

Can I use this on pages as well as posts?

Yes. Enable the page post type, or any other public type, in the settings.

Does this plugin call remote services?

No.

Is it on the WordPress.org plugin directory?

Not yet. It is coming soon to the WordPress.org directory. Until then, download version 1.0.1 from the GitHub release.

Get the plugin

  1. Download version 1.0.1 from the GitHub release.
  2. Upload the auto-floating-toc folder to /wp-content/plugins/.
  3. Activate Auto Floating TOC.
  4. Optional: open Settings → Auto Floating TOC to change heading levels, the title or the post types.

Version 1.0.1 fixes the floating list not appearing on wide screens in block themes. Requires WordPress 6.3+ and PHP 7.4+. Coming soon to the WordPress.org directory.