bulk no-follow for a specific domain?

Joined
Feb 16, 2019
Messages
65
Likes
32
Degree
0
I want to no-follow all links to affiliate program sites, like Amazon for example.

My VA isn't super savvy with html so don't want him to have to edit html for every affiliate link to make it no-follow every time a new affiliate link is added.

Does anybody have a process or plugin that can nofollow specific domains when externally linked?
 
I've set my affiliate links using Thirsty Affiliates. The plugin will automatically add a nofollow tag. If you want to automatically add other tags, then it allows for that too.

Here's their walkthrough on adding other tags: https://thirstyaffiliates.com/knowl...-links-from-getting-indexed-in-search-engines

Edit: Just realized it might not be a good short term solution if you have a ton of existing affiliate links. However, if are just starting out or you don't have many links. It's a good start.
 
Last edited:
Wouldn't need a plugin for it. Use this, and make the regex match your affiliate link path

PHP:
function add_rel_nofollow( $text ) {
    // This is a pre save filter, so text is already escaped.
    $text = stripslashes($text);
    $text = preg_replace_callback('|<a (.+?)>|i', 'add_rel_nofollow_callback', $text);
    //$text = wp_slash($text); //I had to remove this because it was adding undesired backslashes to the output
    return $text;
}

function add_rel_nofollow_callback( $matches ) {
    $text = $matches[1];
    $site_link = get_bloginfo('url');

    if (strpos($text, 'rel') === false) {
        $text = preg_replace("%(href=S(?!$site_link))%i", 'rel="nofollow" $1', $text);
    } elseif (preg_match("%href=S(?!$site_link)%i", $link)) {
        $text = str_replace(array(' rel="nofollow"', " rel='nofollow'"), '', $text);
    }       

    return "<a $text rel=\"nofollow\">";
}
add_filter( 'the_content', 'add_rel_nofollow' );
 
If you're using Wordpress, then https://wordpress.org/plugins/wp-external-links/ works. I use it on all of my sites.
i took a look at this - i see a way to nofollow all external and whitelist some /but no way to do the reverse, where you follow all links, but only nofollow all links from a specific domain (like all links that start with amazon.com). do you have the set up you can share?
 
RankMath has both whitelists and blacklists for this.
 
i took a look at this - i see a way to nofollow all external and whitelist some /but no way to do the reverse, where you follow all links, but only nofollow all links from a specific domain (like all links that start with amazon.com). do you have the set up you can share?

There is an 'Exceptions' tab where you can list all domains/URLs you want to treat as dofollow.

8mw8U2a.png

[moderator note: please embed images, don't link to them]
 
Back