Thank you for this script, it seemed like the ultimate solution for the affiliate links on my blog, but for some reason it doesn’t work on my website.
I have tried several times and pasted the script in the head of the blog post template page, but instead of rel= nofollow - I just see the “#nofollow” at the end of the link.
Any ideas?
WARNING
** Will override all External - rich-text links.
** Sometimes one website have more than one domain (sites group -or- diff url for login and ideas like this) - in this case - do not use this code.
Your site domain for example:
www.paris.com
Before body (On blog CMS page):
<!-- add rel="nofollow" to all rich text block External links -->
<script>
let host = window.location.host; // return www.paris.com
let all_post_links = $('.w-richtext a'); // all a elements inside w-richtext
/* loop throw all a links */
all_post_links.each(function( index ) {
let current_href = all_post_links[index].href; /* return X of Y href */
if(! current_href.includes(host)){
/* if domain do not include host name = outer link => add not follow */
console.log( "Add rel nofollow to: " + current_href );
$( this ).attr("rel","nofollow");
}
});
</script>
Thank you for this! I tried it and it works like a magic.
I keep looking for a more specific way, like to add #nofollow to the link itself and change it to rel nofollow.
Is there any way to add links to dofollow in this code. A few of my sites need a couple of dofollow links I would like to exclude from the nofollow tag.
In general it related to the case. One way is to create array of “exclude” links (Separate by comma).
let host = "hello.com"; // return www.paris.com
let all_post_links = $('.w-richtext a'); // all a elements inside w-richtext
let exclude_from_no_follow = [
"cnn.com",
"nike.org"
]
/* loop throw all a links */
all_post_links.each(function( index ) {
let current_href = all_post_links[index].href; /* return X of Y href */
if(! current_href.includes(host)){
/* if domain do not include host name = outer link => add not follow */
console.log( "Add rel nofollow to: " + current_href );
$( this ).attr("rel","nofollow");
/* EXCLUDE LIST */
for (i in exclude_from_no_follow) {
let exclude_url = exclude_from_no_follow[i];
if(current_href.includes(exclude_url)){
/* DO Something for exclude list */
$( this ).attr("rel","follow");
/* or remove by $( this ).removeAttr("rel")
}
}
}
});
Hi @RoryVB, tried your code but it’s not working. Added it before the body, but it’s not working on my page (check the Notion link).
I can’t believe Webflow doesn’t have this feature. It might be a deal-breaker for me using it, and I REALLY want to move away from WordPress for my main site.
I tried and pasted the code into my project, but it did not work. Maybe I misunderstood where or how to use.
Do you mean that the code itself should be inserted in the head, and the links themselves need to write #nofollow, just to the end of the link. If so, that’s what I did and nothing worked. Can you give me a hint, maybe I misunderstood you.
Just adding my voice of disbelief that this isn’t natively possible in Webflow and that (as usual) it seems the solution seems to be adding code to a platform that prides itself on being no code.
We have marketers who use our CMS and we need to make it as easy for them to do this. This discussion has been going on for five years now, it’s absurd.
Thanks for your reply. I placed it in the head and it still doesn’t seem to be working. I’m trying to add nofollow to the news websites I’ve linked toon my bio page
I’ve added the #nofollow to the end of each of the links but it’s not adding rel=“nofollow”
Fyi, I think the script might have accidentally added rel=“nofollow” to the navbar About link as well as a div with class cms_rte w-richtext that wraps the content starting with ‘Background and Career’.