How to add rel=”nofollow” to just one link in your blogroll

October 20th, 2009

I link to a site that, while I appreciate its hilarity, I really don’t want to positively influence their Page Rank. Page Rank is the assessment that Google has made about the quality of a site; more non-spam links usually correlates to higher Page Rank. You can use a link’s rel attribute – created to describe relationships between documents – to tell search engines that you’re not endorsing a it.

In WordPress, there’s a handy field for setting the rel attribute of a link, except they’ve got some Javascript wizardry in place to prevent you from just typing “nofollow”. A little research revealed lots of plugins to alter all your links in some way, but I didn’t want that. I found a site that allegedly showed how to alter the WordPress code, but that site’s layout had such serious defects that I couldn’t make heads or tales of what it was trying to tell me.

Then I had an idea that was so smart it made me feel stupid: alter the database. Most web software, including WordPress, is essentially a fancy interface to get information into and out of a database1. Bypass the gatekeeper by going straight to MySQL’s command line.

First, find the id of the link you want with the following command:
select link_id, link_name, link_rel from links where link_name like '%Clearingho%'

I searched for links containing the term Clearingho; you should change it to the name of the link you’re looking for.

The first column is link_id, the bit of information you’re looking for. The second is the link name, which I included to confirm that I really am grabbing the right id. Third is the existing rel value; I wanted to make sure I wasn’t about to clobber any existing data.

The link_id in this case was 18 and the existing link_rel value was blank, so it’s a simple update:
update links set link_rel="nofollow" where link_id=18

If you wanted to retain the existing rel information, you could run the following query instead:
update links set link_rel=CONCAT(link_rel, " nofollow") where link_id=18

Refresh your blog and see the new rel=”nofollow” on your suspect link. Congratulate yourself and do a silly dance.

1 Just in case it’s not already obvious, I’d like to clarify that this is not in any way a slur against WordPress or any other database-driven2 software.
2 This buzzword is so 2003.3
3 Yo dawg, I heard you like footnotes, so we put a footnote on your footnote so you can foot while you note.

Tags: ,

Comments are closed.