How to Modify a Wordpress RSS Feed Widget with Rel=Nofollow

I just added an RSS feed widget to my site (see the lower right corner – the DZone links). I frequent dZone a decent amount, and I find a lot of the articles interesting.

However, after some thought I became concerned that ten sitewide external links might be a bit of a drain on my pagerank. If only I could add “rel=nofollow” to all those links. But there’s no option in the RSS Widget to do that.

Well, I decided to dive in and fix it myself.

Where the RSS Feed Widget is Located

This is actually a very simple hack to the Wordpress source files. You’ll need to edit two lines of the file, upload it, and you should be good to go.

The file we’re looking for is “widgets.php” – it should be located in the wp-includes folder. This holds all the functions related to creating widgets and it also holds the standard widgets available in the Dashboard.

We need to scroll down, find the “RSS Feed Widget,” find where the links are created, and add “rel=’nofollow’” to those anchor tags.

Hack It Up – Add Some Code

The function we’re looking for should be around line 935 – titled “wp_widget_rss.” Once you’ve found the function, look for this line – it should be around 965.

$title = "<a class='rsswidget' href='$url' title='" . 
  attribute_escape(__('Syndicate this content')) ."'><img 
  style='background:orange;color:white;border:none;' 
  width='14' height='14' src='$icon' alt='RSS' /></a> 
  <a class='rsswidget' href='$link' title='$desc'>$title</a>";

This creates the “RSS Icon” link to the original feed. There’s a second link in there that makes the link for the title of the RSS feed. To make these nofollow, simply add the phrase rel='nofollow' right after the <a. Be sure to use single quotes around the nofollow – or else you’ll break the PHP statement and cause an error.

When complete, it should look like this. Notice that we’re adding rel=’nofollow’ in two places.

$title = "<a rel='nofollow' class='rsswidget' href='$url' title='" . 
  attribute_escape(__('Syndicate this content')) ."'><img 
  style='background:orange;color:white;border:none;' 
  width='14' height='14' src='$icon' alt='RSS' /></a> 
  <a rel='nofollow' class='rsswidget' href='$link' title='$desc'>$title</a>";

Now scroll down a bit more to roughly line 990. The line we’re looking for creates the individual links to the articles. You should see this bit of code.

echo "<li><a class='rsswidget' href='$link'
  title='$desc'>$title</a>$summary</li>";

Again, add rel='nofollow' right after the <a. The result should look like this.

echo "<li><a rel='nofollow' class='rsswidget' href='$link'
  title='$desc'>$title</a>$summary</li>";
Upload the File

That’s it. Those two small changes should make your RSS Widgets nofollow from now on – preserving your pagerank.

Simply upload the file to the server (be sure to replace the old wp-includes/widgets.php) and reload your site.

If you run into an error, double check that you used single quotes around the ‘nofollow.’ The PHP string is started with a double quote (“), so if you place a double-quote there you’ll prematurely end the string – and cause a parse error.

Bookmark and Share:
  • Digg
  • Furl
  • del.icio.us
  • StumbleUpon
  • MisterWong
  • DZone
  • Technorati

Tags: , , , ,

Leave a Reply