Tag External Links as Nofollow without WordPress Plugin

External Links as NofollowTag External Links as Nofollow without any WordPress Plugin: Here I am sharing a little but important tip for you. It will add rel=nofollow tag to all external links on your sites. External links points to other sites from your site. Adding nofollow tag is important for Search Engine Optimization. You can do this by using some WordPress plugin. But using too many plugins can affect your site’s loading time. So here I am telling you how to do this without any plugin. It’s pretty easy and simple to do. You don’t need coding skills for this.

Also Read: Create Custom Affiliate URLs on WordPress

First of all, for those who don’t know what is the meaning of rel=”nofollow” – No follow tag is a method for stopping Search Engines bots follow any particular links. If you are using many external links on your content and those links are dofollow, Search Engine bots will follow those links. And of course you don’t want that. So you can prevent Search Engine from following these links using nofollow tag. You can also use it for any specific link of your site if you don’t want Search Engine to follow and index them.

Tag External Links as Nofollow without Plugin

All you have to do is adding a code on your WordPress theme. On your Dashboard go to Appearance > Editor. Open your theme’s function file (functions.php) and add the following code. Save the file.

// Add Rel Nofollow To External Links
function wp_nofollow($content)
{
return preg_replace_callback('/<a[^>]+/', 'wp_nofollow_callback', $content);
}
function wp_nofollow_callback($matches)
{
$link = $matches[0];
$site_link = get_bloginfo('url');
if (strpos($link, 'rel') === false)
{
$link = preg_replace("%(href=S(?!$site_link))%i", 'rel="nofollow" $1', $link);
}
elseif (preg_match("%href=S(?!$site_link)%i", $link))
{
$link = preg_replace('/rel=S(?!nofollow)S*/i', 'rel="nofollow"', $link);
}
return $link;
}
add_filter('the_content', 'wp_nofollow');

Backup your functions.php file before editing it. Now you have tagged External Links as Nofollow without any WordPress plugin. Also check out other WordPress related posts Here. Don’t forget to Share this with your friends if you found this helpful and Subscribe to RSS feed for daily updates.

Sharing is Caring
Istiak Rayhan
 

Istiak Rayhan is the founder of RoadToBlogging.com, a blog that aims to make bloggers' journey easier. Istiak loves to help newbie bloggers to build a better blog. Here's more about him.

  • Andrei Chira says:

    What if you want only some external links to be nofollow, not all?
    I’m talking about affiliate links, obviously.
    Let’s say you only got 3-4 domains that you want to nofollow links to.

  • Andrei Chira says:

    I’m looking for automation. I’ve tested some plugins but most of them are old and not working as they should. Right now I’m using Better WordPress External Links which is quite ok but I have to insert domains I want to be followed. Ideal for me is to insert domains I want nofollowed.

  • Deeba Rajpal says:

    I tried and because I am no expert, I messed up my code. I really need to add no follow to my site as I have been penalized by Google. Any help would be appreciated. Thank you

  • Istiak,

    This is exactly what I was looking for. I want the process automated without using a plug in. However, there are some external links I want to be dofollow. Can I override the code edit by adding the rel=follow tag to individual links in posts or pages?

  • Tarun Aarya says:

    Hello Istiak,

    Informative post, I have enjoyed reading this but in the last this code is not working. Kindly check it.

  • >