This WordPress function integrates a customizable Table of Contents (TOC) with Rank Math SEO, supporting shortcode insertion, extensive styling options, and automatic 'SiteNavigationElement' Schema generation for improved search visibility. It can be loaded straight from your theme, without the need to install a plugin.
- Shortcode Driven: Insert
[toc]
in your posts/pages for an automatic TOC. - Extensive Customization:
- Adjust width, font size, background, and more.
- Exclude specific headings or use patterns to exclude ranges.
- Enable hierarchical view or number list styles.
- Smooth scroll with customizable offset for better navigation.
- SEO Enhancement: Integrates with Rank Math to generate
SiteNavigationElement
Schema.
- Clone this repository into your WordPress theme's directory.
- Add the class to your theme's
functions.php
:
require_once get_template_directory() . '/inc/usergrowth-toc.php';
new TableOfContents();
If you're using a child theme use the following code:
require_once get_stylesheet_directory() . '/inc/usergrowth-toc.php';
new TableOfContents();
After installation, simply insert the [toc]
shortcode wherever you need a TOC. The shortcode will generate a TOC styled according to the customizations defined in the class while adhering to font styles and colors set in your theme.
- Reach out on Twitter
- Open an issue on GitHub
For a bug report, bug fix, or a suggestion, please feel free to open an issue.
Pull requests are always welcome, and I'll do my best to do reviews as quickly as possible.