Table Of Contents In The Sidebar

Apr 12, 2009   //   by Hackadelic   //   Featured, WordPress  //  19 Comments
This entry is part of a series, TOC Advice»

2609655539 b644e5e1b2 t Table Of Contents In The SidebarHackadelic TOC Boxes work in the sidebar as well. Out of the box. You can see a live demo on my blog by going to a post’s single view: The TOC box appears at the top of the left sidebar.1 This post here is a good example.

How I did it?

The trick is fairly simple: After enabling shortcode in widgets, I simply added a text widget with no title to my sidebar, and entered the shortcode:

[toc style="margin-bottom:1em; margin-right:1em"]

That’s it.

Since a TOC is only generated in “single mode” (meaning when viewing single posts or pages), the widget occupies no space on the front page or archive pages. In singular views, it expands to the TOC of the current post or page (if it has any headers).

Hence, this is an alternative way of “automatically” adding a TOC to all your posts – complementary to the auto-insertion feature. In particular in blogs that use in-post images extensively, adding a TOC in the sidebar is the less obtrusive and problematic way than auto-inserting it into the post, where it might interfere with the individual post layout / typesetting.

  1. At least it’s at the top at time of this writing. I may move it in the future to another place, or remove it all together. []

19 Comments

Leave a comment

Please ignore these 2 fields:

Blog Categories

I have come here to chew bubblegum and kick ass...
and I'm all out of bubblegum.
-- Nada in They Live