Page table of contents in WordPress
A table of contents that follows the reader through a long article and highlights the current section.
Here is an excerpt of this component's code in WordPress. The full code is free for members, ready to copy into your project.
This component also comes in
The code in WordPress
<!-- wp:group {"className": "toc", "layout": {"type": "default"}} -->
<div class="wp-block-group toc"><!-- wp:html -->
<nav class="toc__nav" aria-labelledby="toc-titre" data-toc>
<p class="toc__title" id="toc-titre">Sur cette page</p>
<ol>
<li><a href="#emplacement">Choisir l'emplacement du rucher</a></li>
<li><a href="#materiel">Le matériel indispensable</a></li>
<li><a href="#colonie">Acquérir sa première colonie</a></li>
<li><a href="#visites">Les visites de printemps</a></li>
<li><a href="#recolte">La première récolte</a></li>
</ol>
</nav>(() => {
if (!document.querySelector(".toc")) return;
document.querySelectorAll("[data-toc]").forEach((toc) => {
const links = [...toc.querySelectorAll('a[href^="#"]')];
const sections = links.map((link) => document.getElementById(link.getAttribute("href").slice(1)));
let frame = 0;
function update() {
frame = 0;
// The active section is the last one whose top has passed the upper third of the window.
const line = window.innerHeight / 3;
let active = 0;<?php
/**
* Plugin Name: Forge, Sommaire de page
* Description: Une table des matières qui suit la lecture d'un long article et surligne la section en cours. Ajoute la composition « Sommaire de page » à l'éditeur de blocs.
* Version: 1.0.0
* Requires at least: 6.6
* Requires PHP: 8.1
* Author: Forge
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: forge-sommaire-page
*:root {
--tc-text: #2b2205;
--tc-body: #4a3d14;
--tc-muted: #6b5a2a;
--tc-line: #eadfb8;
--tc-accent: #a16207;
--tc-active: #713f12;
--tc-ring: #713f12;
--demo-sommaire-page-bg: #fefbf0;
--demo-sommaire-page-text: #2b2205;
}
Free component: copy it freely, including for commercial projects.
Other breadcrumbs and pagination components in WordPress
Breadcrumbs and pagination components in WordPress
A bottom bar with Call, Directions and Free quote that tucks away while visitors read down the page and returns as soon as they scroll up. Built for tradespeople whose customers arrive on a phone.
- Tailwind
- React
- CSS
- WordPress

A slim bar at the top of the page with a message, a link and a close button; once closed, it stays hidden for the period you choose.
- Tailwind
- React
- CSS
- WordPress

A sticky sidebar table of contents for blog posts: it highlights the section being read, shows the reading time left and folds into a list under the title on mobile.
- Tailwind
- React
- CSS
- WordPress

A column of dots on the side of the page that follows the section being read and lets visitors jump to it, with a label on hover and focus.
- Tailwind
- React
- CSS
- WordPress

Step indicator
FreeAn order step indicator: finished steps clickable to go back, the current step announced, upcoming steps locked.
- Tailwind
- React
- CSS
- WordPress

Tooltips in four positions that open on hover, tap and keyboard focus, and close with Escape, as WCAG requires.
- Tailwind
- React
- CSS
- WordPress