Placing a TOC In The Sidebar Revisited – First Aid For Naughty Themes
Some 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:
- Open the file single.php. Near the top you’ll find a statement like this:
<?php get_sidebar(); ?>
- Copy the statement to the clipboard.
- Comment it out like this:
<?php //get_sidebar(); ?>
. Or simply delete it. - Scroll down to the bottom of the file. There you should find a statement like this:
<?php get_footer(); ?>
- Just before it, paste the previously copied statement from the clipboard.
- 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.
- How To Auto-Collapse TOC Boxes
- How To Couple a TOC Box to an Image
- Table Of Contents In The Sidebar
- Placing a TOC In The Sidebar Revisited - First Aid For Naughty Themes
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.