How To Set The WordPress RSS Widget To NoFollow

I mentioned yesterday how you can add an list to your sidebar composed of all the people that are linking to you, but didn’t mention that, by default, all the links are “dofollow”. Because there is no approval process for links included in an RSS feed, some people prefer to set the links to “nofollow” so that Google is aware that you do not directly endorse every link that appears.

The RSS widget doesn’t include the option to set links to nofollow, but that doesn’t mean that we can’t add it. This is going to require a hack to one of the Wordpress core files, widgets.php, which you can find in your wp-includes directory. Because you’re hacking a core file, you will lose these changes every time you upgrade WordPress.

Ready for a little WordPress hackin’? Well, let’s get to it.

How To Hack Widgets.php To Set The RSS Widget To Nofollow

These instructions were written for Wordpress version 2.5.1, so if you’re using another version, your mileage may vary.

  1. This is a really simple hack, but humor me and save a backup copy of widgets.php as widgets.old, so that you don’t spend the next four hours on a four minute hack because you missed an apostrophe somewhere.
  2. Open widgets.php in your favorite editor and on line 1029, you will find function wp_widget_rss. This is the start of the RSS widget section. You don’t need to do anything with this line, but I wanted to include it as a reference in case future WordPress versions move things around.
  3. On line 1069, you’ll find:
    $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>";
  4. If you want to get rid of the RSS icon and the linking title so that the RSS widget blends in with your other sidebar sections, you can either delete the entire line or comment it out by putting a // at the beginning of the line. If you like the way it looks, simply add rel='nofollow' to 2 places to the line so that it ends up looking like this:

    $title = "<a class='rsswidget' rel='nofollow' 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' rel='nofollow' href='$link' title='$desc'>$title</a>";
  5. On line 1079, you’ll find function wp_widget_rss_output. The next line we’re going to modify is under the section. Again, the mention of this line is only provided for reference.
  6. On line 1157, you’ll find:
    echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";

    Add the nofollow attribute to this line by inserting it like so:

    echo "<li><a class='rsswidget' rel='nofollow' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";
  7. Save the file and upload it to your server.

All your RSS links should now be set to nofollow. Remember that because you just hacked a WordPress core file, you will have to implement his hack the next time you upgrade. The only way to avoid this is to stop hacking core files or use a plugin such as Buddy Love that includes the nofollow option.

Share, Bookmark, or E-Mail This Article

9 Responses to “How To Set The WordPress RSS Widget To NoFollow”

  1. Roy Scribner Says:

    This was a huge help – I couldn’t find a way to nuke the RSS icon and link. Thanks a bunch!

  2. ariakristen Says:

    Thanks a ton for posting this. I couldn’t find this code and I’ve really been needing this!

  3. Nimwit Says:

    Could you tell me how I can display the inbuilt rss widget within the index.php without using the actual widget in wordpress. i.e. I’d like to put it somewhere else outside the sidebars.

    Is there a call function?

    N.

  4. Jon Says:

    @Nimwit: The easiest way is to make a call to wp_rss in your page template.

  5. crescent Says:

    Many thanks for the helpful post! It was also OK for 2.7. Thank you again.

  6. Karen @ Blazing Minds Says:

    This is a great tip, had to update a bit for the latest version of WordPress, but besides that it works, perfectly, thanks ;)

  7. Aria Says:

    Karen or someone who has figured this out… where & how do you do this in 2.7+?

  8. protocols Says:

    @Aria: I was searching for my self, and was able to hack it, check out the instructions here: http://pro.to.co.ls/wordpress/how-to-set-the-wordpress-rss-widget-to-nofollow/

  9. Aria Says:

    Thank you SO MUCH @protocols! That is exactly what I was looking for. For some reason, I never found that file on my own.

Leave a Reply

RSS Comment Feed for This Entry | Trackback URL


Close
E-mail It