Adding “nofollow” to Category Links

If you have a lot of categories, here's how to add a "nofollow" to them to prevent diluting your Google PageRank.

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.

No comments yet