How to Add Nofollow Tag to a Certain Domain « RainaStudio
4

How to Add Nofollow Tag to a Certain Domain

Do you want to add Nofollow tag to a certain domain? “Certain domain” – Yes! You probably guess the right meaning “external domain”.

I have been doing Amazon affiliate along with my web developing business. I had to focus on SEO to improve my website ranking on Google search engine. For SEO purpose, I needed to add Nofollow tag for all external links goes to Amazon. I was thinking, how can I add Nofollow tag for Amazon.com domain. I didn’t want to add nofollow attribute manually again and again. Because there was a lot of product review content including affiliate links to the product.

Add Nofollow tag to a certain domain in WordPress

So, what I did! I always love to keep separate my code from core theme functions, file, and code. So I first create a file namednofollow.php theme file directory. Edit the file with a code editor or notepad. Here is the code you have to copy and paste in nofollow.php. Change the value of the $az_url variable to the domain name you want nofollow tag for and save the file.

Note: Don’t put PHP tag if you already have in the file.

We have successfully built the function to add nofollow tag to Amazon.com domain.

Now, we are going to call the nofollow.php file in the functions.php file of our theme. Open functions.php with code editor or notepad. Copy the snippet below and paste it into the functions.php file.

Save the file and we have done. Check the domain URL on your website either it associated with rel=nofollow or not. If you found any error don’t hesitate to comment below.

Infographic: How Nofollow tag works and effects

Infographic-Add-Nofollow-Tag

Conclusion

Usually, to maintain link juice and SEO, you’ll need to add nofollow tag for outbound links. We have a lot of outbound, affiliate and external links to our Amazon affiliate website. I decided to add nofollow tag for all affiliate and product links going Amazon. Above code snippet is the best practice to add nofollow tag or attribute to a specific outbound domain. There are available WordPress plugins does the same work.

We try to add the right value for the WordPress beginner in this tutorial. Let us know if the code snippet works for you.

Editorial Staff
 

Editorial Staff is an in-house team of native WordPress developer and industry columnists.

  • Many thanks.
    That saved me a whole lot of hard work.

  • Sakthivel S says:

    how to add multiple domain names…for the no follow tag.

  • James says:

    Hi, I tried using your code on this page but it’s not displaying properly. For example, these characters arent all valid: ‘~<a.*>~isU’,

    I tried editing it to replace the HTML characters. I made this but it still doesn’t work. Any idea why?

    // Add nofollow to geni.us links
    function add_nofollow( $content ) {

    $az_url = “geni.us”;

    preg_match_all( ‘~isU’, $content, $uri_match );
    for ( $i = 0; $i ” );
    $uri_change .= ‘ rel=”nofollow”>’;
    $content = str_replace( $uri_match[0][ $i ], $uri_change, $content );
    }

    }

    return $content;

    }

    add_filter( ‘the_content’, ‘add_nofollow’ );

  • >