How to manage affiliate links in Squarespace

Add Nofollow.jpg

If you want to add nofollow links in Squarespace, without adding markdown blocks and inserting html everywhere - here’s how.

Google also recommends using the rel=”sponsored” attribute on affiliate links, if possible. So I’ll show you how to do that here as well.

Why does this matter?

Using the right attribution tags on your links is the best way to tell Google what’s what on your site. So from an SEO perspective, its probably worth doing, if you can.

The problem is, doing this manually is tiring, unless you use some code.

The good news is, Ryan Dejaegher created a script that does this for Amazon links automatically. Check out his post to see how it works then come back.

….

Awesome solution right?

Ok now, what if you’ve got 50+ affiliate links from different networks with different URL structures? What do you do?

Here’s what I suggest.

Use URL mapping to simplify all of your affiliate links so they all have the same structure.

In other words, instead of having a bunch of affiliate links on your site that look like this….

https://example.com/?product=2355464&aff_id=37194
https://example2.com/?ref=jaasdasd

You can redirect them all from your own branded site URL like this

https://yoursite.com/recommends/example
https://yoursite.com/recommends/example2

Much prettier right?

From there we can use Ryan’s script to target all of our affiliate links in one shot.

This also allows us to manage and replace them quickly if needed.

But first, here’s how to pretty up those links.

How to cloak your affiliate links

So to Settings > Advanced > URL mapping

Using the same example from above, follow this structure

/recommends/example -> https://example.com/?product=2355464&aff_id=37194 301

Once you’ve done that you can use a modified version of Ryan’s script which I’ve included below.

Now let’s say you use a URL structure like, yousite.com/recommends/affiliatethingy for all your affiliate links.

We can target every external link with “recommends” in it to include a rel=”sponsored” attribute and voila, you’ve automated your affiliate link tagging in Squarespace.

Oh, and not only that, but you can also make all those external links open in a new tab, which has it’s own SEO benefit.

External links (like the ones in blog posts) should ideally open in a new tab.
This way, when your readers inevitably click one of them, they aren't abandoning your site for good.

This reduces bounce rate, increases conversions, increases time on site, and increases pageviews.

How to add rel=”nofollow” links

Using the same example

<script>
(function(){
    window.addEventListener('load', function() {
        var fixAffLinks = function() {
        var affLinks = document.querySelectorAll('a[href*="/recommends/"]');
        
        if (!affLinks instanceof NodeList) 
            
        

        affLinks.forEach(link => {
            link.rel="nofollow"; 
            link.target="_blank";
        })
        }
        fixAffLinks();
    })
    })()
</script>

How to add rel=”sponsored” links

Using the same example

<script>
(function(){
    window.addEventListener('load', function() {
        var fixAffLinks = function() {
        var affLinks = document.querySelectorAll('a[href*="/recommends/"]');
        
        if (!affLinks instanceof NodeList) {
            return;
        }

        affLinks.forEach(link => {
            link.rel="sponsored"; 
            link.target="_blank";
        })
        }
        fixAffLinks();
    })
    })()
</script>
Omari Harebin

Founder of SQSPThemes.com, one of the worlds most trusted Squarespace resources. Since 2015 we’ve helped over 20,000 Squarespace users grow their businesses with custom templates, plugins and integrations.

https://www.sqspthemes.com
Previous
Previous

How to Connect a Squarespace Site to a Third-Party Domain

Next
Next

The Ultimate Guide to Blogging on a Squarespace Site