Table of Contents Plus

A powerful yet user friendly plugin that automatically creates a context specific index or table of contents (TOC) for long pages (and custom post types). More than just a table of contents plugin, this plugin can also output a sitemap listing pages and/or categories across your entire site.

Description

Built from the ground up and with Wikipedia in mind, the table of contents by default appears before the first heading on a page. This allows the author to insert lead-in content that may summarise or introduce the rest of the page. It also uses a unique numbering scheme that doesn’t get lost through CSS differences across themes.

This plugin is a great companion for content rich sites such as content management system oriented configurations. That said, bloggers also have the same benefits when writing long structured articles. Discover how Google uses this index to provide ‘Jump To’ links to your content.

Includes an administration options panel where you can customise settings like display position, define the minimum number of headings before an index is displayed, other appearance, and more. For power users, expand the advanced options to further tweak its behaviour – eg: exclude undesired heading levels like h5 and h6 from being included; disable the output of the included CSS file; adjust the top offset and more. Using shortcodes, you can override default behaviour such as special exclusions on a specific page or even to hide the table of contents altogether.

Prefer to include the index in the sidebar? Go to Appearance > Widgets and drag the TOC+ to your desired sidebar and position.

Custom post types are supported, however, auto insertion works only when the_content() has been used by the custom post type. Each post type will appear in the options panel, so enable the ones you want.

Translations

Translations are more than welcome. The translation file can be found in the languages folder of the plugin, or online in the WordPress repository.

If you have any advice in making it easier to translate, please let me know.

Screenshots

Install / upgrade

Install the plugin by searching for Table of Contents Plus from the plugin add menu, or directly from the WordPress plugins repository.

There are no special upgrade instructions (woohoo!). Overwrite your existing folder with the latest or use the streamlined approach in the plugin menu. Your options will not be lost.

Help

The simplest approach

For the impatient, all you have to do is enable the plugin.

The plugin will apply default settings and produce the table of contents before the first heading on pages (not posts, nor custom post types) with four or more headings.

No shortcodes are needed.

Where’s my table of contents?

  1. In most cases, the post, page or custom post type has less than the minimum number of headings. By default, this is set to four so make sure you have at least four headings within your content. If you want to change this value, you can find it under ‘Main Options’ > ‘Show when’.
  2. Is auto insertion enabled for your content type? By default, only pages are enabled.
  3. Have you got [no_toc] somewhere within the content? This will disable the index for the current post, page or custom post type.
  4. If you are using the TOC+ widget, check if you have the “Show the table of contents only in the sidebar” enabled as this will limit its display to only the sidebar. You can check by going into Appearance > Widgets.
  5. You may have restricted generation to a URL path match. The setting can be found in the advanced section under Main Options.

How do I stop the table of contents from appearing on a single page?

Place the following [no_toc] anywhere on the page to suppress the table of contents. This is known as a shortcode and works for posts, pages and custom post types that make use of the_content()

I’ve set wrapping to left or right but the headings don’t wrap around the table of contents

This normally occurs when there is a CSS clear directive in or around the heading originating from the theme (Twenty Eleven and Twenty Twelve are two themes which do this). This directive tells the user agent to reset the previous wrapping specifications.

You can adjust your theme’s CSS or try moving the table of contents position to the top of the page. If you didn’t build your theme, I’d highly suggest you try the Custom CSS plugin if you wish to make CSS changes.

Try adding the following CSS to allow the wrapping to occur around the table of contents:


h1, h2, h3, h4, h5, h6 { clear: none; }

How do I include the name of the page in the table of contents title?

As the title of the page changes depending on the page you’re viewing, you can use the following special variable to automatically insert the title of the page into the table of contents heading:

%PAGE_NAME%

You can use it as is or place text either side of the variable.

As an example: if your page is named Great Expectations and your table of contents title is set to Contents for %PAGE_NAME%, the final title would read Contents for Great Expectations

My site has 100 pages but I only want the table of contents to appear on 10 of them

You could put [no_toc] on the 90 pages but that wouldn’t be fun… so try the following:

  1. Go to Settings > TOC+ and disable the auto insertion option for pages (or the content type you’re working with).
  2. Add [toc] onto the 10 pages that need them. Note that the table of contents will appear where you placed the shortcode.

Alternatively, you could also experiment with the restrict path option if the pages you want to include the index on all fall within a certain section of your site (eg /doc/).

I want to ignore certain headings

Use the ‘exclude headings’ option if you would like to ignore certain headings. Separate multiple headings with a pipe |. Use an asterisk * as a wildcard to match other text. Note that this is not case sensitive. Some examples include:

  • Fruit* ignore headings starting with Fruit
  • *Fruit Diet* ignore headings with Fruit Diet somewhere in the heading
  • Apple Tree|Oranges|Yellow Bananas ignore headings that are exactly Apple Tree, Oranges or Yellow Bananas

Can I have the table of contents in the sidebar?

Use the TOC+ widget and drag it into your desired position. If you want the table of contents to only be displayed in the sidebar, then make sure you tick that option in the widget.

Unlike Wikipedia, I want all my anchors to be lowercase and use hyphens rather than underscores

There are two options that allow you to adjust the casing and use of hyphens. If you still require more, you can massage it a little more by attaching into the toc_url_anchor_target filter. See the developers section for an example.

I would like to incorporate a sitemap

  1. Create a page for your sitemap (if you have an existing one, use that instead).
  2. Add [sitemap] into your page and save.

The above is the simplest example of integrating a sitemap listing all pages and categories. You can customise the sitemap options under Settings > TOC+ or check out some of the more advanced uses with the sitemap related shortcodes below.

You could also incorporate a sitemap using a text widget and pasting any of the sitemap shortcodes.

The sitemap uses a strange font dissimilar to the rest of the site

No extra styles are created for the sitemap, instead it inherits any styles you used when adding the shortcode. If you copy and pasted, you probably also copied the ‘code’ tags surrounding it so remove them if this is the case.

In most cases, try to have the shortcode on its own line with nothing before or after the square brackets.

Shortcodes

The plugin was designed to be as seamless and painfree as possible and did not require you to insert a shortcode for operation. However, using the shortcode allows you to fully control the position of the table of contents within your page. The following shortcodes are available with this plugin.

When parameters are left out for the shortcodes below, they will fallback to the settings you defined under Settings > TOC+.

Shortcode Description Attributes
[toc] Lets you generate the table of contents at the preferred position. Also useful for sites that only require a TOC on a small handful of pages.
  • label: text, title of the table of contents
  • no_label: true/false, shows or hides the title
  • wrapping: text, either “left” or “right”
  • heading_levels: numbers, this lets you select the heading levels you want included in the table of contents. Separate multiple levels with a comma. Example: include headings 3, 4 and 5 but exclude the others with heading_levels="3,4,5"
  • exclude: text, enter headings to be excluded. Separate multiple headings with a pipe |. Use an asterisk * as a wildcard to match other text. You could also use regular expressions for more advanced matching.
  • class: text, enter CSS classes to be added to the container. Separate multiple classes with a space.
[no_toc] Allows you to disable the table of contents for the current post, page, or custom post type.  
[sitemap] Produces a listing of all pages and categories for your site. You can use this on any post, page or even in a text widget.  
[sitemap_pages] Lets you print out a listing of only pages.
  • heading: number between 1 and 6, defines which html heading to use
  • label: text, title of the list
  • no_label: true/false, shows or hides the list heading
  • exclude: IDs of the pages or categories you wish to exclude
  • exclude_tree: ID of the page or category you wish to exclude including its all descendants
[sitemap_categories] Similar to [sitemap_pages] but for categories.  
[sitemap_posts] This lets you print out an index of all published posts on your site. By default, posts are listed in alphabetical order grouped by their first letters. There are CSS classes for each section, letter and list allowing you to customise the appearance.
  • order: text, either ASC or DESC
  • orderby: text, popular options include “title”, “date”, “ID”, and “rand”. See WP_Query for a list.
  • separate: true/false (defaults to true), does not separate the lists by first letter when set to false.

For developers

How do I customise my anchors?

If you’re still not happy with the anchors, you can modify them to suit your needs through a custom function hooked into the toc_url_anchor_target filter. As an example, place the below code snippet into your functions.php file to convert all anchors to uppercase.

function my_custom_anchor( $anchor )
{
	return strtoupper( $anchor );
}
add_filter( 'toc_url_anchor_target', 'my_custom_anchor' );

toc_get_index( $content = ”, $prefix_url = ” )

Returns a HTML formatted string of the table of contents without the surrounding UL or OL tags to allow the theme editor to supply their own ID and/or classes to the outer list.

Both parameters are optional:

  • $content is the entire content with headings. If blank, will default to the current content found in $post (eg within “the loop”).
  • $prefix_url is the URL to prefix the anchor with. If a string was provided, it will be used as is. If set to “true” then will try to obtain the permalink from the $post object.

These examples assume you are within “the loop”:

  1. Obtain the index for the current page
    echo '<ul id="my_toc">' . toc_get_index() . '</ul>';
  2. Create a listing of all children and their headings
    $children = new WP_Query(array(
    	'post_parent' => get_the_ID(),
    	'posts_per_page' => -1	// get all children
    ));
    while ( $children->have_posts() ) {
    	$children->the_post();
    	echo 
    		'<h3>' . get_the_title() . '</h3>' .
    		'<ul>' . toc_get_index( get_the_content(), get_permalink( $children->post->ID ) ) . '</ul>'
    	;
    }
    wp_reset_postdata();

Versioning scheme

I have adopted the same Ubuntu versioning scheme so the first release is 1107.

Other releases in the same month will be dot releases, eg the second release in July 2011 is 1107.1.

I love it, how can I show my appreciation?

If you have been impressed with this plugin and would like to somehow show some appreciation, rather than send a donation my way, please donate to your charity of choice. Feel free to leave a short note here if you’d like.

I will never ask for any form of reward or compensation. Helping others achieve their goals is satisfying enough :)

Questions or suggestions?

If you have questions or suggestions, please place them below.

1,075 thoughts on “Table of Contents Plus

  1. veannaone says:

    This is such a great addition to my whole Wealthy Affiliate program of developing a navigable website. It has released a logjam in my mind of how to start getting content organized. Awesome. I’m really new to all of this and reading this comments section let’s me know how much I need to learn.

    I do have one question – I would like a button at the end of each TOC section to return to the beginning of the TOC. I have installed the plugin to return to the top of the page, but it goes to the very top of the page. I have started the TOC below my first paragraph and do not want to go past it. Is there functionality in your plugin to do this or do I need to add some code or install another plugin?

    Thanks again for this great addition to my whole online development experience.

  2. I love your plug-in – thanks!

    An interesting little problem. My hosting service has enabled ‘Lets Encrypt’ so I am trying out switching sites to serve https pages. Looks like clearing the cache can be an issue – took a little while before all site images loaded as https. The site I am currently experimenting with has [toc] shortcode on selected pages/posts and on https it doesn’t work. Switching on auto insert it does work (where there isn’t the shortcode already). (I’ve checked on a test site that shortcodes work OK on a fresh install).

    Any ideas other than uninstalling and reinstalling the plug-in? (I’ve already de/activating.)

    Thanks again

  3. Hey there! Thats a great Plugin! Just one Problem:

    It does not appaer on my Homepage. I cant understand why! It only works on posts and pages which are not the homepage…:(:(

    Please help….

  4. J says:

    Hi there,

    Thanks for the nice plugin.
    My header menu floats when page is scrolled and therefor the anchors should be like 30px higher. Is this possible?

    • Mike T says:

      Yep, enable smooth scroll and adjust the height offset (if needed) under the advanced options. The default offset accounts for the WordPress admin bar.

  5. Hello Mike,

    Thank you for your great plugin, I have been using it for quite some time now and I am very happy with it.

    Only recently did I run into something that could be a bug or maybe just a limited option, you tell me.
    I have activated a home brew plugin that adds “Featured posts” to the end of “the_content”. Strange thing is that the widget doesn’t pick up the added headings, but the standard in-post-version does?

    http://www.landmarkscout.com/liberty-park-war-museum-overloon-netherlands/

    Full screen = widget
    Scale browser below 700px = shows standard TOC

    Could you elaborate on this? Thanks in advance!

  6. Pingback: Plugin para crear una tabla de contenidos en WordPress

  7. Pingback: چگونه برای برگه ها و پستهای سایت، (به صورت اتوماتیک) فهرست مطالب تهیه کنیم - وبی لب WebbyLab

  8. It won’t show the TOC on posts on the main page (where multiple posts show), though it shows for each individual post (upon going to that post’s page). Is it possible to show it on the main page, where multiple posts are shown?

    • Mike T says:

      It’s disabled for the homepage but you can enable it in the advanced options in Settings > TOC+. Disabled because it’s not intended to be run when there is a listing of articles (you may get duplicate anchors).

  9. Hi Mike,

    My site is Thrive Best dot com.

    The TOC does not show up in the content but it works in the sidebar.

    I have a friend who has the same theme as mine (Pin Blue) and her TOC works both in content and sidebar.

    Any solution for me?

    Thanks…

  10. Wow…just what i needed for my lengthy FAQ~ But is there s setting that when someone links to a line in the TOC, when it goes to that content they have a link to return to the TOC without having to scroll a few pages to get back?…many thanks
    Tony

  11. Hi. I love your plugin! nice work, very usefull.

    I use toc_get_index() to display the toc in a navbar submenu,

    but the anchors are not provided in post heading (no ‘span id=”…”>…</span')

    this is because I de-activate the toc for post (I don't want duplicate it in post content or in a widget sidebar)

    How can I force the creation of anchors in content?
    There is a filter to apply to the_content()?

    Thanks!

  12. rsr2001 says:

    Mike thank you for your altruistic and wonderful support of TOC+. Do you accept donations to help you support your work… coffee gift cards ….
    Raf
    :)

  13. Pingback: Table of Contents Plus 1601 | dublue

  14. Hi Mike, thank you for this great and easy to use plugin!
    I am using the plugin Aesop Story Telling Engine and I want the TOC of a page/post in a sidebar only. Unfortunately for the sidebar TOC the shortcodes are not yet processed – so the Aesop Chapters (which are actually shortcodes creating h2 HTML) do not show up in the TOC. A TOC at the end of the page with shortcode [toc] shows perfectly all Aesop chapters, too.
    Any idea, how I could get the complete toc into the sidebar?
    Thanks for any hints!!!

    • Mike T says:

      Because the Aesop content hasn’t been created for the page when the sidebar is created, I would not use the TOC+ widget and instead have it produce within the content area. After that, you can use javascript/jQuery to move the TOC to the position you want (in this case, into your sidebar). This was done at http://annualreport.treasury.gov.au/part-2/program-1-1/ with the following simple jQuery:

      if ( $('#content #toc_container').length > 0 ) {
      $('#toc_container').detach().appendTo('#rhs-fixed');
      }

    • Mike T says:

      No idea – do you have a plugin that tries to link up related articles for you? It’s not appearing in the TOC because either the “related” heading is not a HTML heading or the related plugin runs after TOC+.

  15. Pingback: JanPaul999 on "[Plugin: Table of Contents Plus] Scroll offset not working on my site" * Best Wordpress Themes - Reviews

  16. Hi Mike, first of all, great plugin. Thanks. Been using it for a few years and my visitors love it.

    That said, I’m having a problem now after switching to a new theme with a consistent top menu…

    I have set “Smooth scroll top offset” to 50px but it doesn’t do anything – the setting is not working for me.

    Can you please have a quick to see what it could be?

    You can see one of my TOC+’s here: http://boracaycompass.com/beaches-guide/

    Thanks a ton,

    Paul

  17. Hi Mike,

    Really love the Contents plugin, its made my pages look a lot neater.
    I am having a small problem with one of my pages http://thegbear.com/books/

    The layout is with little boxes and I want to centre the Table of Contents at the top of the page but it won’t let me in the backend composer in wordpress. Is there another way i can centre the Contents on a page?

    Thanks:)

  18. I am finding an issue in Mobile pages. When I click a tag from TOC menu it jumps to the right header but at the same time it hides all contents above it.
    Say I clicked tag 1.0.5, it jumps to the 5th header correctly but hides all contents above it i.e. 1.0.1 to 1.0.4.
    I tried on android devices and different browsers… same results.

    Please help.

  19. Hi, thanks for your great plugin!
    One thing that did not work out for me: When using the table in sidebars only, I can use the general settings (TOC+) to change the minimum of headings necessary to create a table. So far, so good. But I cannot switch off or change the title above the table (by default:”Contents”). It would be great if you could change this with the next update or so.
    Best, Dirk

    • Mike T says:

      Sorry but it’s never done that for me? You’ll need to enable your browser’s debugging console to see if there are any issues that is preventing it from saving (eg from other plugins or the theme itself).

  20. Max says:

    Hi Mike, Awesome plugin thanks so much for this. I am using it to show all the posts on my site and i usually post twice a week, as i have been doing this for awhile the list has become very long under each main heading

    is there a way to show the alphabetic characters and only expand to show the posts withing it only once clicked

    • Mike T says:

      sitemap_posts adds a surrounding div around each section of letters with hooks that could be used to apply this affect, so with some javascript and CSS, you may be able to do it? It is a good suggestion though.

      Here is the structure:

      div.toc_sitemap_posts_section
          p.toc_sitemap_posts_letter
          ul.toc_sitemap_posts_list

  21. Hi,
    It is really good plugin for my site.
    Can I change the title in the TOC without changing the title of the actual contents.
    I want to make the title in the TOC a little bit shorter.
    cheers,

  22. Pingback: test jump link

  23. Pav says:

    Hey there Mike,
    Love the plugin.
    I am doing an experiment, trying to make it work with a slider (paginated pages).
    My results so far http://goo.gl/B7I7oB
    Do you have any ideas how to make it work with pages like this?
    Thanks again, this is one of the best supported free plugins I have ever seen.

    • Mike T says:

      It will probably have something to do with smooth scroll so first turn that off to see if it works. If you want smooth scrolling, then it would need to trigger the slide action of the sliding library you’re using.

  24. Pingback: Table of Contents Plus: A Great WP Plugin for More Traffic (Free) — FAT Stacks Entrepreneur

  25. Hello; Great plugin !! verrry happy with it..

    My question.:

    Is it possible to create three TOC+ on one page ??
    So if….how to do that and what is the procedure to create three TOC+ on one page.

    Regards,

    Jan

  26. Hello Mike, thank you for your plugin, it rocks. And I mean it!
    I have a problem:

    1) On posts where I activated TOC+ all the H1,H2,x text went from black to gray. Nothing changed on the pages without TOC+. How to change it and keep TOC+?

    Thank you. Website is amazingtelescopes dot com, check out any post, not page.

    • Mike T says:

      This plugin encapsulates the headings in html span tags. So if there are visual differences, then your theme has different styles for headings with span tags. I checked your site and this is the case for you, see line 249 of http://www.amazingtelescopes.com/wp-content/themes/hueman/style.css?3f2818


      .entry h1 span, .entry h2 span, .entry h3 span, .entry h4 span, .entry h5 span, .entry h6 span {
      color: #BBB;
      }

      To change it, see if you can insert your own custom CSS with something like:


      .entry h1 span, .entry h2 span, .entry h3 span, .entry h4 span, .entry h5 span, .entry h6 span {
      color: #444 !important;
      }

  27. Pingback: Test Matrix Table of Contents - Critical to Success

  28. We’d like to style the TOC… like implementing a decimal and some extra spaces after the number (“1. First Section”), or bold the first level, etc. How might we do this?

    • Mike T says:

      You can do all that with some custom CSS. Just inspect the table of contents and you’ll see some selectors you can use to add your styles to. Examples:

      For the dot after the number:

      .toc_number::after {
      content: '. ';
      }

      For the bolded first level headings:

      .toc_list li ul {
      font-weight: normal;
      }
      .toc_list > li {
      font-weight: bold;
      }

  29. VS says:

    The plugin created a ToC on a page that we did not want it, and despite deleting hte plugin we cannot remove the ToC, can you help? <link removed>

    • Mike T says:

      I haven’t tested this plugin with any multilingual plugins so I’m not sure if it would behave as intended, however if each of your different languages were a different site or install, then it should be fine. That said, perhaps the multilingual plugin may do it for you?

Leave a Reply