How to add rel=”nofollow” to WordPress blogroll links

I was playing around with WordPress trying to find out how to open links in new windows (i.e. using target=”_blank”). I’m still getting to used to WordPress’ templating system and familiarizing myself with the include structure.

Then I found out that Google and other search engines may lower your PageRank if they find out you link to other sites in a way to boost page rank which could negatively affect your ranking in search results. So I decided that some links that show on my pages (e.g. BlogRoll links) should have a rel=”nofollow” attribute.

I looked around and found this blog entry which led me to the correct template file but suggests changing

$output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
to
$output .= '<a href="' . $the_link . '"' . $rel . $title . $target. ' rel="nofollow">';

This seems a bit hack-ish and not so elegant since he doesn’t append rel=”nofollow” to the $rel variable. His $rel variable should be set up like this:

$rel = $bookmark->link_rel;
if ( '' != $rel ){
$rel = ' rel="' . $rel . ' nofollow"';
}else{
$rel = 'rel="nofollow"';
}

Anyways, I looked some more and found this blog entry which suggests editing the template responsible for editing the blogroll links. This method adds another checkbox called “nofollow” to the list of other valid values for the rel attribute. This is the preferred approach since it allows me to be more selective about which links have “nofollow” and which do not.

This entry was posted on Tuesday, January 22nd, 2008 at 11:49 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Related Posts

Leave a Reply