secrets to adding rel nofollow tags to affiliate links

It is really very important to add rel nofollow tags to all of your existing amazon affiliate links so that google bot will not follow all those links which are just leading to sales page of amazon. This is very important so that your site ranking will not be affected.

So, in this article you will learn how to automatically add rel nofollow tags to all those existing amazon affiliate links on your website without using any wordpress plugin.

Not only will this work with amazon.com link strings, but this method will also work wtih amzn.to or amzn.com and any kind of affiliate links you have in your wordpress site.

If this method is implemented, it will add nofollow tags on, not just one affiliate links, but all amazon affiliate links including its shortened versions.

The good thing about this method is that, since you are not using any plugin, there is no additional consumption of your server resources.

Before I proceed, let me tell you this, there are so many wordpress plugins available in the wordpress repository. What I mean there are so many nofollow plugins available there.

Some or many of them are good. They can make you add rel nofollow tags on all of your external links: And let me share some of the good ones I used before that I no longer use now because of the disadvantages they all have.

WordPress Plugins With External Nofollow Functionality

So Here below are the good nofollow wordpress plugins I used before:

Pros of Using External nofollow Plugins

The good thing about these plugins I mentioned above is that, they are capable of putting a nofollow tags to all of your external links globally. This only means all of your affiliate links leading to external site will be added automatically with re follow attributes.

Cons of Using External nofollow Plugins

But the problem is that, if you are going to enable the functionality of these plugins, they will add rel nofollow tags on all of the external links found on your wordpress site. And that includes those good links leading to informative sites which can help you rank well in SEO.

ALSO READ:  Fix Your WordPress Slow Performance: Comprehensive Guide

To be specific, all the external and helpful outside links like we wikipedia, and some similar sites with links which you intentionally put on our website to help readers find even more useful information will be integrated with rel nofollow tags.

Those sites can help your SEO ranking and at the same time can help your website readers or visitors to find and read even more information, but the plugins I mentioned above will affect those links by adding rel nofollow on them all.

So here is a free solution:

Rel Nofollow Script – Can Add Rel Nofollow Tags on Certain External Links

The script I have provided below will automatically add rel nofollow tags on certain domain strings you want to be added with nofollow attributes. This means it is not only limited to amazon, but you can also use this on all of your affiliate links strings.

Where To Place This Rel Nofollow Script?

You only need to add the below scripts at the last part of your theme functions, you can find in your website’s server. You can also directly go to your theme editor on your wordpress dashboard under appearance and locate the Theme functions and place the below script at the bottom part of it.

The good thing about this is that, you only need to add the main domain of your affiliate links. Like for example: amazon.com, or go.magik.ly.

You only need to put the main domain of the affiliate links and all of the link strings coming from those domains will be added with rel nofollow tags including the main domain.

So far, I have found no wordpress plugins available in the wordpress repository that can do this feature:

So here below are the nofollow script you can use and implement right away on your affiliate sites

1. Script to Add Rel Nofollow To A Single Affiliate Domain

This is for single URL strings:

ALSO READ:  How to Fix Common WordPress Errors Quickly and Efficiently

In my example below, I used amazon.com. So, you need to replace it with your own affiliate link. And there is no need for you to add http, https, and https://www. But just add the main domain name with dot com like the example below.

Again, let me remind you as I already mentioned above. If your affiliate link is https://www.amazon.com/afflink-strings-richard1234, then you only need to add amazon.com like the example below:

// Add no-follow tags for specific domain strings
function add_nofollow( $content ) {

    $az_url = "amazon.com";
    preg_match_all( '~<a.*>~isU', $content, $uri_match );

    for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) {
        if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] )
             && ( preg_match( '~' . preg_quote( $az_url ) . '~', $uri_match[0][ $i ] ))
            ) {
            $uri_change = trim( $uri_match[0][ $i ], ">" );
            $uri_change .= ' rel="nofollow">';
            $content = str_replace( $uri_match[0][ $i ], $uri_change, $content );
        }
    }

    return $content;
}

add_filter( 'the_content', 'add_nofollow' );

2. Script to Add Rel Nofollow To More Than One Affiliate Domains

The script below will add rel nofollow on multiple affiliate links. In my example below, I use amazon1.com, amazon2.com and amazon3.com.

So, if your affiliate links are a https://www.amazon1.com/ref-joe1234, you only need to put the main domain of the affiliate link which is amazon1.com. And do the same with the rest of the affiliate links you want to be added with nofollow attributes.

// Add no-follow tags for specific domain strings
function add_nofollow( $content ) {

    $az_url = "amazon1.com";
    preg_match_all( '~<a.*>~isU', $content, $uri_match );

    for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) {
        if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] )
             && ( preg_match( '~' . preg_quote( $az_url ) . '~', $uri_match[0][ $i ] ))
            ) {
            $uri_change = trim( $uri_match[0][ $i ], ">" );
            $uri_change .= ' rel="nofollow">';
            $content = str_replace( $uri_match[0][ $i ], $uri_change, $content );
        }
    }

    $az_url = "amazon2.com";
    preg_match_all( '~<a.*>~isU', $content, $uri_match );

    for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) {
        if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] )
             && ( preg_match( '~' . preg_quote( $az_url ) . '~', $uri_match[0][ $i ] ))
            ) {
            $uri_change = trim( $uri_match[0][ $i ], ">" );
            $uri_change .= ' rel="nofollow">';
            $content = str_replace( $uri_match[0][ $i ], $uri_change, $content );
        }
    }

    $az_url = "amazon3.com";
    preg_match_all( '~<a.*>~isU', $content, $uri_match );

    for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) {
        if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] )
             && ( preg_match( '~' . preg_quote( $az_url ) . '~', $uri_match[0][ $i ] ))
            ) {
            $uri_change = trim( $uri_match[0][ $i ], ">" );
            $uri_change .= ' rel="nofollow">';
            $content = str_replace( $uri_match[0][ $i ], $uri_change, $content );
        }
    }

    return $content;
}

add_filter( 'the_content', 'add_nofollow' );

In the example above, the number of domains that can be added with rel nofollow tags are 3 domains. But you can make it 4 or even more affiliate domains.

So, if you have four or more affiliate domains, just duplicate the script in the middle. Here below is the script in the middle you need to duplicate.

    $az_url = "amazon.com";
    preg_match_all( '~<a.*>~isU', $content, $uri_match );

    for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) {
        if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] )
             && ( preg_match( '~' . preg_quote( $az_url ) . '~', $uri_match[0][ $i ] ))
            ) {
            $uri_change = trim( $uri_match[0][ $i ], ">" );
            $uri_change .= ' rel="nofollow">';
            $content = str_replace( $uri_match[0][ $i ], $uri_change, $content );
        }
    }

Make sure that you duplicate the right code in the script. You can definitely understand this by just comparing the script for the single domain and the script for the multiple domains.

Additional Info About Adding Rel Noffolow Script.

If you have successfully implemented the script above in your websites, what will happen is:

  • amazon.com will be added with nofollow tags
  • amazon.com/ref-joewills-20 will be added also with nofollow tags.
  • https://www.amazon.com will have nofollow tags on it.
  • https://www.amazon.com/your-affiliate-link-strings will also be added with nofollow attributes.
ALSO READ:  Is WordPress Good for Beginners? An Easy Guide to Get Started

So, that’s all about adding rel nofollow tags on specific domains and domain strings. After you implement this method, you can inspect the page source of your website using any web browser of your choice. And you will see that there are rel nofollow tags on all of the links you implemented with this method.

If you found this article helpful, please share this with your friends or others in your social media.

Similar Posts

26 Comments

  1. What is the point of distributing scripts that you cannot copy?

    1. Richard Hans says:

      Hey! Good day to you, sorry for the inconvenience. I haven’t notice that this post is also protected with the plugin I use. Don’t worry, I have already disabled the copy protection from this page. You may copy the code now. Have a nice day to you.

  2. Awesome! It worked on the first shot. Can you add a function to make those links opened in a new tab? Thanks

    1. Richard Hans says:

      Wow. That’s great. Happy to know that.

  3. Syed Saadullah Shah says:

    Hello I followed the tutorial but how to exclude other external links from being nofollowed?

    1. Richard Hans Aguilar says:

      All the other external links will not be affected by the script in this tutorial as long as you did not add the domain name of the external links in the script I mentioned in this tutorial

  4. products_submenu says:

    What’s up friends, its great paragraph concerning tutoringand entirely defined,
    keep it up all the time.

  5. black bean chipotle meat snack stick says:

    I savor, result in I found exactly what I used to be
    taking a look for. You’ve ended my four day lengthy hunt!

    God Bless you man. Have a great day. Bye

  6. Piece of writing writing is also a excitement, if you
    be familiar with after that you can write if not it is complicated
    to write.

  7. ufabet ทางเข้า says:

    Wow! At last I got a weblog from where I know how to in fact
    take helpful data concerning my study and knowledge.

  8. link alternatif bk8 says:

    Hi there to all, how is everything, I think every one is getting more from this web page, and your views are fastidious in support of new viewers.

  9. I do trust аll thе ideas y᧐u hаve offered on үⲟur post.
    Τhey arre reaⅼly convincing аnd wilⅼ ⅽertainly
    ԝork. Nonetһeless, the posts arre veгy short for starters.
    May you pⅼease prolong thеm a littⅼe from subsequent tіmе?
    Ƭhank yоu for the post.

    Look аt mʏ web pɑge … Byron

  10. Thank you for sharing your thoughts. I really appreciate your efforts and I am waiting for your next post thank you once again.

  11. development company says:

    We absolutely love your blog and find many of your post’s to be exactly I’m looking for.
    can you offer guest writers to write content available for you?
    I wouldn’t mind creating a post or elaborating on most of
    the subjects you write related to here. Again, awesome blog!

    My web-site … development company

  12. new homes minneapolis mn says:

    Wonderful blog! Do you have any tips for aspiring writers?
    I’m planning to start my own blog soon but I’m
    a little lost on everything. Would you suggest starting with a free platform like WordPress or go for a paid option? There are so
    many options out there that I’m completely overwhelmed ..

    Any tips? Many thanks!

  13. TAS Rego Check says:

    You actually make it appear really easay along ith your presentation but I in finding
    this matter tto bee really one thing that Ithink I’d never understand.
    It kind of feels too comple and extremely extensive for me.
    I’m having a look forward in your next put up, I’ll try to get the cling of it!

    Alsoo visit my blog post … TAS Rego Check

  14. Yesterday, while I was at work, my sister stole my iphone and tested to see if
    it can survive a 30 foot drop, just so she can be a youtube sensation. My apple ipad is now broken and
    she has 83 views. I know this is totally off topic but I had to share it with someone!

    Feel free to visit my blog post: Gloria

  15. flea treatment poisoning in cats says:

    Hmm it looks like your blog ate my first comment (it was super long) so I guess
    I’ll just sum it up what I had written and say, I’m thoroughly enjoying your
    blog. I too am an aspiring blog writer but I’m still new to everything.

    Do you have any tips and hints for beginner blog writers?
    I’d definitely appreciate it.

  16. joker 123 says:

    Hello, after reading this awesome post i am too delighted to share my experience here with friends.

  17. Thank you so much for the script – works like a charme!

  18. Hey Richard,

    Excellent writeup! Thanks for the great post. Regarding your comment..

    “If your affiliate link is https://www.amazon.com/afflink-strings-richard1234, then you only need to add amazon.com like the example below”

    Is there a way to apply nofollow to an “exact match” portion of the URL? For affiliate links, I use my custom slugs and redirect them to the affiliate links so I can easily change the products if my recommendation changes in the future.

    Example: http://mywebsite.com/recommends/product-name

    Every affiliate link in all of my blog posts start with “mywebsite.com/recommends/” and I’m wondering if your script can target those as nofollow, but not touch other internal links on my site that begin with “mywebsite.com/”.

    Unrelated, what does your script do if a targeted external link is already tagged with rel=nofollow? Does it skip those?

    Thanks again for all your help!

    1. Richard Hans Aguilar says:

      Thanks for your comment. In your situation, just add your mywebsite.com/recommends/ to the script I provided. If your external links already have no follows, the script will skip them.

    2. Richard Hans Aguilar says:

      Thanks for your comment. The answer to your question is ===> YES it can. You only need to add your ““mywebsite.com/recommends” to my script. And that will surely work.

  19. 스웨디시 says:

    Hello! I’ve been reading your blog for a long time now and finally got the
    bravery to go ahead and give you a shout out from New Caney
    Tx! Just wanted to say keep up the excellent work!

  20. Donn Hissong says:

    Greatly appreciated this post! It’s brimming with valuable insights and conveyed in an captivating way. Looking forward to more content like this. Amazing effort!

    1. Richard Hans Aguilar says:

      Thanks for leaving a nice comment here. Have a nice day ahead.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.