This code adds an anchor to each heading and generates a TOC list that is inserted before the article content.
After making changes, test your site for errors and verify that the TOC displays and functions correctly. Make sure all TOC links scroll to the corresponding sections of the article.
#toc {
margin: 20px 0;
padding: 10px;
background-color: #f9f9f9;
border: 1px solid #ccc;
}
#toc h2 {
margin-top: 0;
}
#toc ul {
list-style: none;
padding: 0;
}
#toc li a {
color: #333;
text-decoration: none;
}
After making changes, test your site for errors and verify that the TOC displays and functions correctly. Make sure all TOC links scroll to the corresponding sections of the article.
Adding a TOC via theme code gives you full control over its appearance and behavior, but it requires care and accuracy when editing code. If you’re not confident in your programming skills, consider using plugins to add a TOC.
Top 5 plugins for adding a TOC in WordPress
Here is an overview of the top 5 plugins for adding a TOC in WordPress to help you improve the structure and navigation of your articles, enhancing user interaction with content and optimizing SEO.
1. Easy Table of Contents
Easy Table of Contents automatically adds a TOC to posts, pages, and custom post types on your site. The plugin provides flexible settings for where and how the TOC is displayed, including the ability to exclude specific headings. Users can choose from several themes and customize the TOC’s appearance to their preferences.
- Downloads: 300,000+
- Rating: 4.5 out of 5
- Features: multiple bullet styles, automatic insertion, compatibility with various page builders
- Best for: WordPress beginners
- Price: free
2. Table of Contents Plus
Table of Contents Plus is a powerful plugin that creates a TOC and manages related elements such as sitemaps and copyright notices. The plugin is easy to use and supports a wide range of settings, allowing users to fine-tune the TOC’s appearance and behavior.
- Downloads: 300,000+
- Rating: 4.6 out of 5
- Features: indexing tools for pages, including content indexing for sidebars
- Best for: sites with long pages that require indexing
- Price: free
3. SimpleTOC – Table of Contents Block
SimpleTOC is a Gutenberg block that makes it easy to add a TOC to your posts and pages without using shortcodes. This plugin is ideal for those who prefer simplicity and don’t want to dive into complex settings. SimpleTOC automatically updates the TOC when the document structure changes.
- Downloads: 4,000+
- Rating: 5 out of 5
- Features: editor block widget for sidebars, column block support, compatibility with non-Latin text
- Best for: Gutenberg users
- Price: free
4. LuckyWP Table of Contents
LuckyWP Table of Contents offers numerous settings for creating a responsive and beautifully styled TOC. The plugin supports multi-level TOCs (e.g., H1–H6) and allows users to choose whether sections are collapsible. LuckyWP also includes widgets to add TOCs to sidebars or footers.
- Downloads: 80,000+
- Rating: 4.9 out of 5
- Features: compatibility with multiple page builders beyond Gutenberg, customizable appearance, SEO-friendly
- Best for: Elementor, Beaver Builder, and WPBakery users
- Price: free
5. Ultimate Blocks
Ultimate Blocks is designed specifically for Gutenberg and includes a TOC block along with other useful blocks such as FAQ and social sharing buttons. This plugin is ideal for those looking for a comprehensive solution to enhance their articles with various blocks that improve interactivity and functionality.
- Downloads: 30,000+
- Rating: 4.9 out of 5
- Features: various block types for different functions, including call-to-action and testimonial blocks
- Best for: WordPress experts
- Price: free
Adding a TOC to your WordPress posts provides readers with a clear navigational structure, making it easier for them to dive into your content. This not only increases user engagement by allowing them to jump straight to the sections they’re interested in, but also significantly reduces bounce rate, since visitors tend to stay on the site longer rather than leaving after a quick glance. In addition, a well-organized TOC improves your site’s SEO by logically structuring content, helping search engines better understand and index your pages.