SimpleTOC — Table of Contents Block

Description

Add a Table of Contents block to your posts and pages. The TOC is a nested list of links to all heading found in the post or page. To use it, simply add a block and search for “SimpleTOC” or just “TOC”.

The maximum depth of the toc can be configured in in the blocks’ sidebar among many other options. There can hide the headline “Table of Contents” and add your own by using a normal heading block.

SimpleTOC is open-source and developed on GitHub Pages. If you find a bug or have an idea for a feature please feel free to contribute and create a pull request.

Spin up a new WordPress instance with the SimpleTOC plugin already installed.

Features

  • Zero configuration: Add the SimpleTOC block to your post and that’s it.
  • Minimal and valid HTML output.
  • No JavaScript or CSS added. Unless you activate the accordion menu.
  • Designed for Gutenberg.
  • Style SimpleTOC with Gutenberg’s native group styling options.
  • Inherits the style of your theme.
  • Translated in multiple languages. Including German, Japanese, Chinese (Taiwan), Dutch, Brazilian Portuguese, French, Spanish and Latvia.

Customization

  • Add background and text color with Gutenberg groups.
  • Native block support for wide and full width.
  • Control the maximum depth of the headings.
  • Choose between an ordered, bullet HTML list. Or indent the list.
  • Select a heading level or turn it into a paragraph.
  • Disable the h2 heading of the TOC block and add your own.

Compatibility

  • GeneratePress and Rank Math support.
  • Works with popular AMP plugins.

Credits

This plugin is forked from pdewouters and uses code from Easy-Table-of-Contents

Many thanks to Tom J Nowell and and Sally CJ who both helped me a lot with my questions over at wordpress.stackexchange.com

Thanks to Quintus Valerius Soranus for inventing the Table of Contents around 100 BC.

Screenshots

  • SimpleTOC block in Gutenberg editor.
  • SimpleTOC in the post.
  • Simple but powerful. Customize each TOC as you like.
  • Control the maximum depth of the headings.
  • SimpleTOC styled with Gutenbergs native group styles.
  • SimpleTOC Advanced Features
  • Gutenberg Heading block: Set a custom anchor
  • SimpleTOC hidden in the accordion menu.

Blocks

This plugin provides 1 block.

  • SimpleTOC Adds a Table of Contents.

Installation

SimpleTOC can be found and installed via the Plugin menu within WordPress administration (Plugins -> Add New). Alternatively, it can be downloaded from WordPress.org and installed manually…

In Gutenberg, add a block and search for “SimpleTOC” or just “TOC”. Please save your content before you use the block.

FAQ

How do I add a background color to SimpleTOC using Gutenberg groups?

Select the block and select “group” in the context menu. Apply “background color”, “link color” and “text color” to this group. SimpleTOC will inherit these styles. You would like to use this styled SimpleTOC group next time you write a post? Convert it to a reusable block.

How to exclude a single heading from the TOC?

If you really want to hide a single heading from the table of contents, then add the CSS class “simpletoc-hidden” to a heading block. You can find this field in the same place as the HTML anchor field: In the Block > Advanced sidebar. But first, think about the reason you would like to hide a specific heading. Maybe you would like to remove all headings of a specific depth level. Then there is an option for that in the blocks options in Gutenberg. If you think this heading should not be part of the toc perhaps it is not needed in the post itself?

I would like to save my SimpleTOC settings as default. Is that possible?

You can convert your configured SimpleTOC block into a reusable block in Gutenberg. It will keep its settings. This way, you can use your desired settings for each new post by adding the reusable block.

How to add a div tag wrapper to the TOC?

If you add a custom class to the SimpleTOC block in “Advanced” and then “Additional CSS Class(es)” a div with that class will be wrapped around the HTML output. You can force this with a filter, too.

Example:

add_filter( 'simpletoc_wrapper_enabled', '__return_true' );

How to allow developers to exclude specific headings programmatically?

Use the ‘simpletoc_excluded_blocks’ filter. For example, this code will exclude heading blocks that are inside a column block.

Example:

add_filter( 'simpletoc_excluded_blocks', function ( array $blocks ) {
    $blocks[] = 'core/column';

    return $blocks;
} );

How do I change the color of the accordion menu?

The heavy plus character I used can not be colored with css without hacks. But you can change the icon to something else and change the color of the new icon.

.simpletoc-collapsible::after {
    content: "✖";
    color: #e94c89;
}

How do I add SimpleTOC to all articles automatically?

I don’t see an easy solution at the moment. SimpleTOC is only a block that can be placed in your post. If there was a plugin that adds blocks to every post, then this would be the solution. I think this should be another separate plug-in to keep the code of SimpleTOC clean and … well, simple.

Reviews

27 Նոյեմբերի, 2022
I'm not a code and I can't judge of the real optimization of this plugin but it is simple to use and clean. Much appreciated.
7 Նոյեմբերի, 2022 1 reply
I like the plugin a lot. It's simple. It works pretty well and has a few configurations but not too many. Thanks for it! I am using it to learn Wordpress blocks development, which coming from PHP I think it's quite a challenge. Blocks change the development weight from PHP to JS/React a lot!
31 Հոկտեմբերի, 2022
The beauty of SimpleTOC is that you can add it to longer posts that need a Table of Contents, with the ability to choose which Heading levels should be shown and other options. Nothing fancy ... and that's what I like about this plug-in. Thanks / Danke to Mark.
23 Հոկտեմբերի, 2022 1 reply
A great plugin allowing a Table of Contents to be created with minimal input. A great follow-up service too. Marc was extremely helpful and reviewed my query within minutes of posting. He guided me through what I needed to do, and he was able to update me on my query. Super service.
14 Սեպտեմբերի, 2022 1 reply
This is a fantastic plugin. It's much simpler and more lightweight than any of the other options I came across. It also makes an awesome learning tool for someone dipping their toes into custom block creation. It was great to be able to look at the code and think wow, this totally makes sense!
Read all 47 reviews

Contributors & Developers

“SimpleTOC — Table of Contents Block” is open source software. The following people have contributed to this plugin.

Contributors

“SimpleTOC — Table of Contents Block” has been translated into 16 locales. Thank you to the translators for their contributions.

Translate “SimpleTOC — Table of Contents Block” into your language.

Interested in development?

Browse the code, check out the SVN repository, or subscribe to the development log by RSS.

Changelog

5.0.52

  • Fix: wp_set_script_translations undefined in older WordPress installations.

5.0.51

  • Fix: Accordion menu CSS alignment.

5.0.50

  • Fix: Identifier ‘i’ has already been declared
  • Fix: SimpleTOC will not nag the user about changed content in the editor anymore. Therefore I removed the corresponding option from the settings.
  • Fix: Minor changes to accordion css.

5.0.45

  • Feature: Option to render SimpleTOC heading as paragraph.
  • Fix: Added margin to the bottom of the accordion menu.

5.0.43

  • Compatibility with WordPress 6.1
  • Feature: Hide SimpleTOC in an accordion menu. Adds minimal JavaScript and css styles if enabled.
  • Feature: Option to change SimpleTOC block heading level.
  • Fix: Accordion menu can now be added multiple times.
  • Fix: Accordion styling in Gutenberg editor.
  • Fix: Minor accordion styling fixes.
  • Fix: Added JavaScript and CSS for the accordion menu by using standard methods.

5.0.36

  • Feature: Spin up a new WordPress instance with the SimpleTOC plugin already installed.
  • Fix: Better handling for simpletoc-hidden class to hide headings. Thank you blronaldhuereca!

5.0.34

  • Feature: Moved list controls to toolbar and rearranged settings to fit block order.
  • Feature: Filter for developers to wrap toc with a div tag. Thank you rafaucau!
  • Fix: Minor localization tweaks.

5.0.31

  • Feature: Filter for developers to exclude specific blocks. See faq for details. Thanks rafaucau!
  • Feature: Easier development with @wordpress/env to start a dev environment. Thanks rafaucau!

5.0.28

  • Feature: Change the TOC headline in the block options. Thank you Philipp Stracker!

5.0.17

  • Feature: Support for custom Anchor IDs in headings. Thank you Matthias Altmann!