Add nofollow to the category specific links in WordPress

After websites became more popular, search engines grew bigger and bigger and so their influence got even stronger. Suddenly, it became really important to have a website included in the search results. New websites were constantly added to search engines and it was hard for an individual to have a website in top ten search results.

To help organize searches, search engines like Google had to find a way to rank websites and give some priority to ones over the others. It sounded logical that a website with more links to it is also a more popular one. Of course – if other people link to your website, your site must have something interesting about it, right? Yeah, while that would be perfect in a perfect world, it wasn’t good in practice. People started spamming links to their site because any link would matter. So you could have found tons of spam messages in forums, comments and everywhere spammers had access to. More links you had, more points in the search engines you would get. Something had to be changed to stop that.

What’s the difference between follow and nofollow:

Let’s quickly see the difference between two kinds of links. While the regular links are followed and being indexed by search engines, adding nofollow to them simply tells search engines that you don’t want those links to count as important to a page rank. So, if you put nofollow links to comments, spammers wouldn’t have many benefits from it.

Follow and nofollow links

But, after nofollow was introduced in 2005 as a solution to stop spam, people found a way to take advantage of the new idea. They would place a nofollow link to certain pages just so their other pages would get more attention from search bots. And that’s where smart people who work for search engine companies had to make another change. Back in 2009, they decided to change the way Page Ranks were calculated.

Now you might wonder why even care about nofollow links if they won’t be recognized by search engines. Well, even if the link isn’t recognized by a search engine as important, it doesn’t mean that link isn’t important to you. You can still get referral traffic from it, and adding the noffolow to it will only stop search engines from following it. Simple as that.

In order to stop spam, WordPress will automatically assign nofollow to all user-submitted links so you won’t have to worry about that.

While you might want to keep many of your links available for search engines, there will definitely be those you want to exclude. For example, you probably don’t want paid links, comment section or links in your forum to have follow on them. That’s when you need to edit HTML code a little bit.

Add nofollow to a single link:

If you need to add nofollow to a single link, you can do that easily by adding rel=”nofollow” to it:

<a href="" rel="nofollow">Link Text</a>

Add nofollow to the entire category:

But if you want every link in the entire category not to be followed (maybe you have a category dedicated to paid articles), you will need the following piece of code which will tell WordPress how to handle the links:

  1. Open functions.php file
  2. Copy and paste the following code:
  3. function nofollow_cat_posts($text) {
    global $post;
    if( in_category(1) ) {
    $text = stripslashes(wp_rel_nofollow($text));
    return $text;
    add_filter('the_content', 'nofollow_cat_posts');
  4. Go to Posts->Categories
  5. Choose a category and open it
  6. Find the ID number in the URL
  7. Use the ID in the 3rd line of code and change that number found in the brackets:

    if( in_category(1) ) {

  8. Save changes

Don’t forget; nofollow links are as important as follow ones – not every link needs to be your ladder to a page rank. And don’t forget that modern search engines have complex methods of calculating the importance of your site, so don’t be afraid to use nofollow links where you need them.


This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *