Placing a TOC In The Sidebar Revisited – First Aid For Naughty Themes

Jun 28, 2009   //   by Hackadelic   //   WordPress  //  2 Comments
This entry is part of a series, TOC Advice»

Santa Lulu Reacts to Your Christmas Request with AlarmSome time ago, I wrote a tip about placing a TOC in the side bar. As it now turns out, this tip does not work on all themes. Here’s why, and what you can do about it.

The crux is that the tip depends on the HTML rendering order (the “source ordering”). It relies on themes adhering to the content-first principle. That is: It relies on content being rendered first, so that the TOC plugin has a chance to collect headings. When sidebars are rendered first, the TOC plugin has not seen any headings yet, and nothing is rendered.

Nowadays most themes are good citizens in that they adhere to the content-first principle, a lucky situation much of which is owed to SEO considereations. But there are exceptions, like the Oriental theme.

Here’s what you can do about it:

  1. Open the file single.php. Near the top you’ll find a statement like this:<?php get_sidebar(); ?>
  2. Copy the statement to the clipboard.
  3. Comment it out like this: <?php //get_sidebar(); ?>. Or simply delete it.
  4. Scroll down to the bottom of the file. There you should find a statement like this:<?php get_footer(); ?>
  5. Just before it, paste the previously copied statement from the clipboard.
  6. Repeat the procedure with the file page.php.

Note that this fix probably won’t work with every theme. Only themes which base their layout on CSS, not source ordering, can be fixed like this. But that should be the case with most themes today.

That’s it for today.

Cheers and happy blogging.

Entries in this series:
  1. How To Auto-Collapse TOC Boxes
  2. How To Couple a TOC Box to an Image
  3. Table Of Contents In The Sidebar
  4. Placing a TOC In The Sidebar Revisited - First Aid For Naughty Themes
Powered by Hackadelic Sliding Notes 1.6.5

2 Comments

  • Thank you very much. That helped quite a lot. 😉 The only thing left to complain is that it renders the widget anyway, but I guess that’s something within wordpress. (what I’m trying to say is that I see the “empty” widget also within all pages other than “page.php” and “single.php” but nevermind.)

    • GhostLyrics, that’s your theme. It gives the widget a padding, or a minimum size, so you see even an empty widget. On mine an empty widget has zero size.

Blog Categories

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