Anchor yourself with easy jump links

Anchor and chain linksI’ve previously explained how WordPress is an internal linking powerhouse, but even the super-easy and super-powerful WordPress link dialog box doesn’t contain a built-in way to add jump links.

Jump links, also known as anchor links, are links that take you to a specific part of a page, instead of the default top location.

I personally prefer the term jump links because it captures the idea that these links let readers “jump” to various parts of a page (and also because technically all links use the HTML anchor tag…so every link is an anchor link).

So…what if you want to link to something other than the top of the page?

Good news: Yes you can!

News that might be not-quite-so-good: You have to do a little bit of manual fiddling to get it to work, including (gasp) adding a tiny piece of HTML code to your page.

Why use jump links in the first place?

Links should be useful. And sometimes that means linking within the content of a page.

F’rinstance, here are some situations that might call for jump links:

  • A long post or page with a table of contents at the top. Each item in the table of contents links to a subhead lower down on the page.
  • The handy “return to top” link at the bottom of a page.
  • At the top of a sales page, you can include a link saying “Want to go straight to the price?”
  • Footnotes.[1]

Let’s say, for example, that you have a long page, and you want to let readers jump straight to Part 1, Part 2, or Part 3 of the page from a table of contents at the top. Here’s what you need to do:

Step 1. Figure out where the jump will start and end

At the top of your page, you’ll have some text that you want to turn into clickable links to sections of your page. Maybe a list, like this:

Part 1: Thesis

Part 2: Antithesis

Part 3: Synthesis

And then lower down in the body of your page, you’ll have subheads, using Header 3 style, that match those table-of-contents listings.

Let’s link up the table-of-contents entry “Part 1: Thesis” with its subhead. To do that, we’ll start with the subhead itself.

Step 2. Locate the end point of the jump in HTML view

Visual tab and HTML tab

The Visual and HTML tabs on the WordPress post box

At the top of your WordPress post box, there are two tabs, labeled Visual and HTML. Most of us do our writing entirely in Visual view, which is fine for most purposes. This is one of the few times you’ll need to take a peek into the HTML code of your page.

If you click the HTML tab, you’ll see that the text of your post is still there, interspersed with HTML tags. What you want to do is find the subhead where you’ll be pointing your jump link. If you’ve used the WordPress visual editor to give this subhead a Header 3 style, it will be wrapped in the appropriate HTML tags like this:

<h3>Part 1: Thesis</h3>

Step 3. Add an id attribute to your HTML

Now that you’ve located the HTML tags that enclose your subhead, you need to add one small piece of code to the first tag, so that this:

<h3>Part 1: Thesis</h3>

becomes this:

<h3 id="thesis">Part 1: Thesis</h3>

Pay attention to the spacing: Leave a space before the “id” but make sure there’s no space between the closing quotation mark and the greater-than symbol. And remember, you’re not deleting any characters, only adding.

You get to choose the text between the quotation marks — it will become part of your link URL, so use only letters and numbers, and no spaces inside the quotation marks.

You can add the id=”linkname” attribute to any HTML tag, not just <h3>. Subheads are easy to find and it makes sense to use them, but you’re not limited to them for jump link purposes.

Step 4. Switch back to Visual view and make sure it looks OK

Now click the Visual tab again and make sure the subhead — and everything after it — looks all right. “All right” in this case means “visually indistinguishable from before you added the id=”linkname” attribute.” In the Visual tab, your subhead should look unchanged.

Step 5. Add a link at the origin point

Now that you’ve prepared the end point of your jump link, you can use the built-in WordPress link dialog box to add your link in the usual way: Highlight the text you want to turn into a clickable link (in this case, the table-of-contents entry corresponding to the subhead) and click the link icon in your editing toolbar.

Now, instead of putting a full URL here, simply type the number sign (#) followed by the word you placed between the quotation marks in your id=”linkname” attribute, like this:

Optionally fill in a title, then click the blue “Add Link” button to save the link. Your table-of-contents entry should now show up as a blue, underlined link.

Step 6: Test the link

Once you’ve added the link, I suggest previewing the page to make sure your jump link works as intended. In the Preview tab, click the link and see if you jump down (or up) the page to your desired end point.

If it works, you are good to go.

If it doesn’t (if you click the link and nothing happens, for instance, or if you are taken to your home page instead of the same-page end point you expected), first double-check your HTML change.

It’s also possible that your theme or one of your plugins is rewriting your link URLs. The solution is to use the full URL of the page plus the “#linkname”, instead of just “#linkname” in the URL field, like this:

The tricky part here is that you are linking to the same page you’re currently editing, and if that page is unpublished, it won’t show up in the list of “existing content,” so you’ll have to manually type the complete and correct URL, make sure it ends with a forward slash, and append the “#linkname” text.

Now you can easily create tables of contents, footnotes, and intra-page jump links. Jump away!

1. ^ See how that little superscript “1″ took you right down here to the bottom of the post? Neat, huh? The thing to remember with footnotes is that you always want to provide your readers an easy way to jump back up to exactly where they came from, or you’ll lose them. That’s why the little “^” symbol at the beginning of this footnote is another jump link that goes right back up to the footnoted text. If it’s good enough for Wikipedia, it’s good enough for me!

Image adapted from dorron on Flickr, used under a Creative Commons ShareAlike License

My very favorite thing about WordPress 3.1

Chain link image by John-Morgan

Yesterday I told you all about the WordPress admin bar, my second-favorite feature of the latest release. Today I’ll tell you about my very favorite feature of WordPress 3.1 — the thing that made me bounce delightedly and exclaim “holy shit I love this!”

Yes, I really did say that. Out loud.

(WordPress 3.1 was released in late February, and if you haven’t already upgraded, please do! If you need some help, watch my video tutorial on upgrading WordPress, or follow my illustrated instructions.)

Ready to feel the power?

Follow the links

It’s the “add link” dialog box!

How can anyone get this excited about a dialog box?

Well, consider that in the Olden Days of last month, linking to one of my own blog posts was a complex multi-step process.

Let’s say I was writing a blog post (like this one) and I wanted to link to another of my blog posts (like I did in the first line, where I linked to yesterday’s post).

I would have to get the full URL of that post, which normally would mean opening another tab showing my site, navigating to the post I wanted, and copying the address from the browser bar. Only then could I click the little chain-link icon in my editing screen, which would open the “add link” dialog box where I could paste the address I’d just copied.

And I did this frequently, because if I’ve written about related topics before, it’s a service to my newer readers to let them know about it. Plus cross-linking to your own stuff is a good practice for search engine optimization (though not as important as having outside sites link to you).

But WordPress has now made the “add link” dialog box into an internal linking powerhouse!

In your editing screen, when you highlight some text (or an image) you want to turn into a link, and then click on the little chain-link icon, this dialog box pops up:

The "add link" dialog box, showing all the pages and posts on your site

You can still type or paste a URL directly into the top field, optionally add a title, and your link is good to go. There’s still a handy checkbox to specify whether you want the link to open in a new window or in the same window (that topic deserves a whole post of its own…).

But look out below! Beneath “Or link to existing content” (you might have to click the gray triangle) there’s a list of every post and page on your website!

Linking to your own content just got super-duper easy:

  • If you want to link to a recent post, it will be right there on top, because the list is organized in order of publication.
  • If you know when you published the post or page, you can scroll directly to that date to find it.
  • Or you can search your site, right from within the dialog box, to instantly find the exact post or page you want.

When you locate the post or page you want to link to, click it and the URL and Title fields will be automagically filled in:

After searching for a post, clicking on the post title fills in the URL and title fields

Of course you’re free to edit the link title (this is what shows up when you hover over the link with your cursor — as distinct from the anchor text, which is the clickable link text itself — the piece of text you highlighted before clicking the “add link” button).

And that’s that! It’s now a one-step easy process to find and link to any post or page on your website, right from within the “add link” dialog box!

Update: I’ve added a tutorial on adding jump links that point to locations within a post (or page).

WordPress Plugin: Broken Link Checker

Broken Link Checker is a tremendously useful plugin, one that I include with all my WordPress installs. It does exactly what its name suggests: Checks your blog posts and pages for broken links (automatically, in the background) and lets you fix them easily, without having to visit and edit each individual post.

How to install and configure Broken Link Checker

You’ll want to install this WordPress plugin in the usual way. And this is one of those plugins that works great with the default configuration. Just activate it and let it do its magic!

Now that it’s installed, here’s how to use it to find and fix those pesky broken links.

You can access this plugin in two ways: In the sidebar of your WordPress Dashboard, visit Settings –> Link Checker or visit Tools –> Broken Links.

Settings --> Link Checker in the WordPress sidebar

Tools --> Broken Links in the WordPress sidebar

Visiting and changing the plugin settings

When you visit Settings –> Link Checker, you’ll see a screen that displays the number of broken links at the top, along with a button labeled “re-check all pages.” Clicking this button will, you guessed it, re-check all the links on your site. It may take some time if you have a lot of posts or pages, but it can be really useful if you’ve just done some site overhauling.

Broken Link Checker settings page, showing number of broken links at the top

Even if you don’t use the “re-check all pages” button, Broken Link Checker will be working in the background, checking all your links at the interval specified in the “Check each link” field. The default is every 72 hours.

Also on this settings page is something called “Broken link CSS.” If the checkbox is checked, the default setting is for broken links to be marked with a strikethrough. You could change this to any style you want, but the important thing to remember is that anyone viewing your site will see broken links marked this way. If you don’t want to visually call out the fact that your links are broken, just uncheck the box.

Personally I think you’re better off catching and fixing those links than visually marking them for all to see. Which you can also do quite easily with this plugin. Read on to find out how.

Finding and fixing broken links

If you click the “found (number) broken links” link on the settings page, OR if you visit Tools –> Broken Links, you’ll be presented with a handy list of all your broken links, showing the page or post title, the link (anchor) text, and the non-working URL, as shown here:

Detail of Broken Links page

In this example, I have a link to a post on my own blog that’s not working (oops, I probably changed the permalink), a link to an external site that’s not working, and a link to an image on one of my blog posts that’s not working (probably left over from when I was hosting my images somewhere else in my hosting system).

Fortunately, these are pretty easy to fix. I can find the updated URL of my own post and the blog image. If the external site has changed, I can use a new one…or simply make the text no longer be a link. I can even tell the plugin to stop telling me a certain link is broken if I don’t want it to show up in my broken link list anymore.

Just hover your cursor over the link in question, and several options appear below the post title and link URL:

Both post-editing and link-editing options appear when you hover your cursor over one of the broken links

The three options underneath the post/page title are:

  • Edit, which opens the post editing screen so you can manually change the text and/or link
  • Delete, which deletes the post (click with caution!)
  • View, which shows you how this post looks to a blog visitor

However, it’s often quicker and simpler to edit the link directly, right within this plugin screen. To do that, choose one of the four options that appear underneath the URL:

  • Details, which shows you a log of how many times the link has failed, if there was an error code generated, etc. You probably won’t need to click on this unless you like reading error logs (hahahaha!)
  • Unlink, which simply makes the text (or image) no longer a link. Very useful and simple solution. Just don’t use for text like “click here” or buttons, because inviting people to click on something unclickable ends up confusing them.
  • Exclude, which tells the link checker to stop reporting instances of this link as broken. In my example, links to photobucket.com kept coming up as broken, despite the fact that I could visit the site just fine. So I ended up excluding them.
  • Edit URL, which lets you directly edit the web address the link is pointing to without visiting the Edit Post screen. If the page in question has a new address, you can paste it here. Just remember to click “Save URL” after you’ve made changes in the URL field.

You’ll probably end up using Unlink and Edit URL the most. They’re super-useful.

Once you’ve made a change that fixes the broken link, it will blink a soothing green-is-for-go color and disappear from this page. Nice job! If you fix a link and the link checker doesn’t seem to “get” it, you can wait awhile, force a recheck, or click “Exclude” to give yourself a clean slate.

And that’s it! Useful, quick, and really easy to use, Broken Link Checker is a must-have plugin for WordPress sites of all sizes.

Here’s the plugin creator’s Broken Link Checker page, and a description of an upcoming version (0.9), and the author’s discussion of a user survey, including descriptions of some planned features.