Contents Nav for Bricks
A Bricks element that builds a table of contents from the headings in a part of the page, highlights the section being read, and turns into a dropdown when the space is narrow.
Version: 0.1.0 · Requires: WordPress 6.0+, PHP 8.1+, Bricks · See the live demo
What it does
- Reads the headings you choose (H2, H2 and H3, and so on) from a part of the page and lists them, indented by level.
- Gives any heading without an id one, so the links work.
- Highlights the section being read as you scroll.
- Scrolls smoothly, and allows for a fixed header.
- Replaces the list with a select menu when the space is narrow, measured on the element itself.
- Can stick while the page scrolls, and hides itself when there are too few headings.
Installation
- Upload and activate the plugin. Bricks must be active.
- In the Bricks editor search for Contents Nav (General group).
Quick start
- Put the element beside your content, such as in a sidebar column.
- Set Read headings from to a class that wraps your content, such as
.article. The default is the main part of the page. - Choose the heading levels.
Settings
- Title, Read headings from, Heading levels, Hide when fewer headings than
- Highlight the section being read, Scroll offset
- Stick while scrolling and the distance from the top
- Become a dropdown at (px) — default 260; 0 keeps the list
- Link, current, line and title colours, and link size
Tips
- Add the class
cn-skipto a heading to leave it out. - Sticky needs a column that is taller than the element, and no overflow hidden on its parents.
Known limits
- The list is built in the browser from the headings on the page, so it is not part of the page source.
- Headings added after the page has loaded are not listed.