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.
Syndicate RSS Feeds on your Website for Extra Content said this on May 4th, 2010 at 11:32 am
[...] can read this guide to find out how to hack the WordPress source to make the RSS Widget nofollow. You’ll need to know a bit of PHP, but it’s not too [...]
Harry Brown said this on May 20th, 2010 at 1:16 pm
RSS Feeds are really very helpful and you could get site and news updates from it.’;:
Syndicate RSS Feeds on your Website for Extra Content | Search Engine Optimization - Dtriplers Internet Marketing Solutions said this on July 14th, 2010 at 4:25 am
[...] read this guide to find out hοw to hack the WordPress source to make &…. Yου′ll need to know a [...]
Articles.vp.ly » Syndicate RSS Feeds on your Website for Extra Content said this on July 16th, 2010 at 12:54 pm
[...] can read this guide to find out how to hack the WordPress source to make the RSS Widget nofollow. You’ll need to know a bit of PHP, but it’s not too [...]
Angelina Ramirez said this on July 28th, 2010 at 3:43 am
RSS feeds are really great because you are always updated with the latest news or blog posts.~`*