This is just and addendum to a previous tip about in-page anchors: I don’t know if anyone noticed, but I’ve made some little changes to those indexes.
There’s no more jQuery to add, but some hints to make the headings more accessible: I’m trying to get those fucking Site Links on Google, too — and it isn’t “so” easy.
First of all, I made the menus’ layout closer to WordPress Codex: it depends on how you stylized them via CSS, so I can only suggest you to have a look at the example (just in the upper-right side of the page).
As you might notice, WordPress chose AJAX to handle the show/hide toggle link… while I’m preferring jQuery instead. You don’t have to make any change there.
I changed other 2 things you could find useful: the 1st implies to use slugs to replace the existing anchors’ IDs. My previous post suggested as follows:
<h3 id="chapter-1">Chapter 1</h3> <h3 id="chapter-2">Chapter 2</h3> <h3 id="chapter-3">Chapter 3</h3>
To be clearer, the above IDs used the same semantic prefix – in these cases, chapter- – with ascending integers to differentiate the anchors. Here’s what you should have after modifying them:
<h3 id="lorem-ipsum-dolor-sit-amet">Lorem ipsum dolor sit amet</h3> <h3 id="ut-wisi-enim-ad-minim-veniam">Ut wisi enim ad minim veniam</h3> <h3 id="typi-non-habent-claritatem-insitam">Typi non habent claritatem insitam</h3>
I really hope that it helps with the automatic Rich Snippets‘ creation: otherwise, it’s even preferable. Of course, remember to change the anchors accordingly.
The 2nd point I considered is “optional” and lots of people discourage its use: anyway – if you haven’t them elsewhere on the same page – you could add accesskeys to the links.
<div id="toc"> <h4 id="toc-label">Index </h4> <ol id="toc-toggle"> <li><a href="#lorem-ipsum-dolor-sit-amet" accesskey="1">Lorem ipsum dolor sit amet</a></li> <li><a href="#ut-wisi-enim-ad-minim-veniam" accesskey="2">Ut wisi enim ad minim veniam</a></li> <li><a href="#typi-non-habent-claritatem-insitam" accesskey="3">Typi non habent claritatem insitam</a></li> </ol> </div>
Some browsers could override them by default, but they won’t hurt: just make sure you aren’t using the same accesskey for two or more different links.
Another thing: looking at the Jeff Starr’s blog (a very useful resource you must read) I noticed anchors to go back to the TOC in plain headings. Those are especially useful to avoid mouse scrolling.
<h3 id="lorem-ipsum-dolor-sit-amet">Lorem ipsum dolor sit amet <a href="#toc" rel="toc">↑</a></h3>
I suggest you to maintain the rel="toc" in the end of the anchor, because it’s a standard reference. Optionally, it’s possible to handle the link with jQuery to get a better scroll to the TOC — I’ll explain how later.
That’s it for now: feel free to post any questions and/or suggestions in the comments (now open to public guests). For those who cares, I didn’t finish this blog’s adoption yet.
