Adding “nofollow” to Category Links

This post has been marked as old. The code might no longer work. Comments have been disabled as this is no longer maintained. Use the search on the right to find a newer tutorial.

One of my clients (StuckInCustoms) has a huge number of categories. They wanted to use the default WordPress functions to list all the categories in the sidebar and list the categories a specific post is in, but also wanted to add rel="nofollow" to all of the links.

The following code should be placed in your custom_functions.php file if you’re using Thesis, or your functions.php file if you’re using any other theme:

This is what it’s doing:
– We created a filter called add_nofollow() which takes in the content of something, looks for <a>‘s and uses the wp_rel_nofollow_callback() function to add rel="nofollow" to it.
– The function the_category() outputs links with rel="category tag" already, and we don’t want to rel’s in the code. So we wrote a filter add_nofollow_cat() that first finds and removes the rel="category tag", then runs the filter add_nofollow().
– We ran the filter add_nofollow() on the function wp_list_categories(), and ran the filter add_nofollow_cat() on the function the_category().

Note: I don’t provide SEO advice to clients beyond my post Search Engine Optimization for WordPress, so don’t ask me if this is right for you.

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk

Reader Interactions

Comments are closed. Continue the conversation with me on Twitter: @billerickson

Comments

  1. Chris (from L.C) says

    Bill,

    It was great to hear your talk at WordCamp here in Houston.

    Adding rel=nofollow to an internal link is, except in extreme cases, a bad idea. Though Google does occasionally choose to ignore it (Twitter links are a good example), doing it on internal pages is pretty poor SEO practice. Despite what many people thought, PageRank doesn’t “leak” (as in, you’ll lose it to linked-to pages). Having authority passed to those categories can only help the domain, never hurt it, assuming what’s behind the link is not spammy.

    Some have argued that categories/archives cause duplicate content issues. Google is pretty smart about this, especially on the established blogging platforms (WordPress, MT, Blogger, etc.). I’ve yet to see penalization for having categories and posts crawable.

    Matt Cutts addresses this issue directly in these two links:
    http://www.youtube.com/watch?v=4SAPUx4Beh8&feature=player_embedded
    http://www.mattcutts.com/blog/pagerank-sculpting/

    To quickly summarize both of those, he basically says “don’t nofollow internal links, and only nofollow external links you can’t trust”. Yes, he is indicating that it’s a good thing to have followed links out to trusted sites. It’s something that is a ranking signal (albeit a small one).

    I’d be happy to answer any other SEO questions that you might have. Feel free to email me any time!

    Later,

    Chris

    • Bill Erickson says

      Thanks for the thorough response.

      I added that note to the bottom of the post because I don’t keep up with SEO and don’t know what’s right or wrong. A client requested this, so I figured out how to do it.

      I’ll forward your comment to my client because I’m sure he’d be interested in this too.

      Thanks again

  2. Chris (from L.C.) says

    No problem!

    WordPress is great out of the box for SEO (if you simply leave it alone), but it’s easy to get sucked into a myth and make unnecessary changes. I’ve been there many times myself when I was starting out dabbling in WordPress and optimization.

  3. Desk Coder says

    This only added no follow to the last category link, not any of the previous ones. I am using WordPress version 3.4 and the category sidebar widget. Thanks

    • Bill Erickson says

      Sorry about that. The code here is really old and not recommended, so I’m marking it as such.