The link cloaking I’ve added to the Stallion Responsive Theme and Stallion WordPress SEO Theme is a very cool feature.

Why Hide/Cloak Affiliate Links?

There are two reasons to hide/cloak affiliate links (any link).

1. Hide the source of the link from your visitors so they don’t know they are about to go to an affiliate site AND so other affiliates can’t easily steal your affiliate links (apparently it’s a problem).

2. To protect a sites link benefit, Google does not want us linking to affiliate sites and other sites we don’t recommend. Unfortunately Google took away the only way to tell Google etc… a link shouldn’t pass link benefit when it changed how nofollow links work (stupid Google). A nofollow link used to pass no link benefit to the page it was linking to and the ‘saved’ link benefit was reused on the followed links from the page. Google currently deletes the link benefit of nofollow links so we should avoid using nofollow!!!

WordPress Theme Link Cloaking

Stallion uses advanced javascript and css coding to ‘hide’ affiliate links from Google and other search engines, it works because search engines don’t read the javascript/css coding as a link (it’s not a link, the javascript makes it act like a link). The downside of this is a small number of your real visitors (estimated below 10%) who have javascript turned off will not see the links either, they will only see the anchor text of the link.

This is not actually cloaking the links for your visitors, you can still see the source of the links as you hover over them (when javascript is turned on), but to search engines they are cloaked/hidden.

If you run the Massive Passive Profits Autoblog Plugin or the WP Robot Autoblog Plugin Stallion can automatically ‘hide’ the affiliate links from search engines.

Note: the link above to WPRobot is an affiliate link that has been cloaked using a simple PHP redirection script (see later) AND uses the Stallion link cloaking feature to ‘hide’ it from search engines, this is the code I used:

<span class="affst" title="outboundz" id="1">WP Robot Autoblog Plugin</span>

After reading this link cloaking tutorial you will be able to setup similar cloaked affiliate links on your WordPress blog.

If you run the Massive Passive Profits Autoblog plugin and have turned link cloaking on your Amazon affiliate links etc… will be cloaked/hidden from search engines, same for WPRobot, most affiliate links are automatically cloaked by Stallion Responsive. If you view source of an autoblog page you will see the affiliate links have been replaced with some code that looks like a link (the javascript/css coding converts it to a link), you can see the code later in this tutorial.

How to Cloak/Hide a Link Using Stallion

Lets say you have a standard text link like this one:

<a href="https://stallion-theme.co.uk/">Stallion Theme</a>

This links to the Stallion home page “https://stallion-theme.co.uk/” with the anchor text “Stallion Theme”. This is the actual link: Stallion Theme.

It’s very easy to turn it into a hidden link using Stallion by changing it to.

<span class="affst" title="tests" id="https://stallion-theme.co.uk/">Stallion Theme</span>

You place the URL https://stallion-theme.co.uk/ in the id=”” part of the code and the anchor text (Stallion Theme) before the closing </span>. As long as “Cloak Affiliate Links” is turned on under the “Stallion Promotion Options” page it will be cloaked/hidden.

That’s it the link is cloaked/hidden from Google. You can do this manually to any link that Stallion has access to within the content of a post or page linking to any page.

You can do the same with image links by replacing the anchor text with image code:

<span class="affst" title="tests" id="https://stallion-theme.co.uk/"><img src="https://stallion-theme.co.uk/wp-content/uploads/premium-wordpress-theme.png" alt="Stallion Theme" /></span>

Note if a visitor has javascript turned off they would see an non clickable image only.

Basically if you have any link with format:

<a href="...">...</a>

It can be replaced with the code above.

WordPress Simple PHP Redirection Script to Hide AND Cloak Links

The above feature is pretty cool on it’s own, you can use it to save all that link benefit that would be wasted by linking to affiliate sites directly or using nofollow links, but it doesn’t hide where the link goes to, to your visitors. Now the interesting part is when we bring in other tools.

I’ve been using a free very simple PHP redirection script for years. I have it installed on this domain and use the script for a lot of affiliate links, especially Clickbank products (the WP Robot autoblog link above uses the script, hover over it and you’ll see the ….co.uk/go/go.php?id=1 URL.). This means if an affiliate product is no longer available (happens a lot with Clickbank products) you edit one file related to the redirection script and every link to that affiliate product is changed (you could link it to a similar affiliate product for example).

You can get the free PHP Redirection Script here (note used the cloaking code to hide this link, no link benefit wasted) and install it on one of your domains. I put it under the folder /go/ and renamed some of the files (I forget why), but doesn’t really matter where you put it you can keep the default settings.

My settings results in links like this:

https://stallion-theme.co.uk/go/go.php?id=##

Where ## is a number.

If you go with the defaults your setup will be something like this:

http://www.domain.com/ccount12/click.php?id=##

To incorporate this script into Stallion edit the links.js file or the links.php file found in the /stallion-responsive/js/ folder (links.php is the inline javascript version added to Stallion Responsive 8.2).
Note: in Stallion WordPress SEO 7 it was test.js under /stallion-wordpress-seo/, same file, minor changes.

You will find this line of code:

case 'outboundz': theURL = 'https://stallion-theme.co.uk/go/go.php?id='; break;

Change to:

case 'outboundz': theURL = 'http://www.domain.com/ccount12/click.php?id='; break;

This will now use your PHP redirection script to cloak links (obviously you change domain.com to your domain :-)).

You could use almost any PHP redirection script that outputs a unique id/code

Note: there are multiple examples I’ve used starting “case” etc…. like “case ‘testing2’: theURL = ‘http://www…..” each line can be changed to your needs, I’ve used tests2, testing, testing2 and outboundz. You can change them to use your redirection scripts. If you are using the inline js option edit the links.php file instead, there’s only the case ‘outboundz’: theURL…. line.

Log into the PHP Redirection Script and add a link, it should be given ID = 1 so will go to the link:

Link Cloaking PHP Script

http://www.domain.com/ccount12/click.php?id=1

We use this code to incorporate this link into a WordPress post or page:

<span class="affst" title="outboundz" id="1">Anchor Text of Link</span>

When you create a second cloaked link it will be ID = 2 so change the id=”1″ to id=”2″ and so on.

In this way you can have as many cloaked links as you have IDs with this script.

This concept will work with pretty much any redirection script. If you have a script that generates URLs like

http://www.domain.com/UNIQUECODE1

You add

case 'testing': theURL = 'http://www.domain.com/'; break;

To the links.js file (or links.php file is using the inline js option) and build your link code like:

<span class="affst" title="testing" id="UNIQUECODE1">Anchor Text of Link</span>

Already used more than one PHP redirection script, not a problem you can add more than one type of link format. To use the two examples above, in your links.js file (note the second line uses testing2 instead of testing, each line needs a unique string (can be almost anything)):

case 'testing': theURL = 'http://www.domain.com/ccount12/click.php?id='; break;
case 'testing2': theURL = 'http://www.domain.com/'; break;

Now link code

<span class="affst" title="testing" id="1">Anchor Text of Link</span>

Will use the top format (testing) and

<span class="affst" title="testing2" id="UNIQUECODE1">Anchor Text of Link</span>

Will use the bottom format (testing2).

Automation of Link Cloaking

Want a bit of automation in your link cloaking so you aren’t endlessly copying and pasting IDs etc… Not a problem.

I’ve been using this technique on affiliate sites with thousands of links and cloak the lot with a simple technique.

I’ve created a small number of affiliate sites using Shareasale datafeeds and use a simple PHP redirection script to cloak the links with format:

http://www.domain.com/buy-now.php?id=##

Create a file called buy-now.php (you can name it anything you like as long as you change relevant parts below to match the filename) and put it in the root of your domain (can put it anywhere, but easier for me to explain if it’s in the root :-))

<?php
$id=$_GET['id'];
header('Location: http://www.shareasale.com/m-pr.cfm?merchantID=SHAREASALEMERCHANTID&userID=YOURSHAREASALEID&productID='.$id);
?>

Replace
SHAREASALEMERCHANTID : you get this from the datafeed
and
YOURSHAREASALEID : that’s your Shareasale User ID

Add this to your Stallion links.js file:

case 'tests4': theURL = 'http://www.domain.com/buy-now.php?id='; break;

And use the link format:

<span class="affst" title="tests4" id="UNIQUEPRODUCTID">Buy Now</span>

UNIQUEPRODUCTID : is the Unique product ID from the Shareasale datafeed.

Your affiliate links will now look like this when hovered over:

http://www.domain.com/buy-now.php?id=123456

When building the site (normally with a database import script like WPRobot) you would use the above link code format instead of a normal affiliate link, in this way it’s all automated. Some of my sites where built before I used this technique, I edited the MySQL database (ran a few SQL queries) to search and replace the original affiliate links with nofollow links to the sort of code above (will explain how in a comment when I have the time).

I’d link to an affiliate site that uses this technique, but it’s never a good idea to show your affiliate sites around as makes it easier for Google to find and downgrade them (Google hates affiliate sites).

You can use the concept on any affiliate source that uses a general format with a unique code to identify each product like “http:www.ALLLINKSHAVETHISBIT?ID=UNIQUETOEACHPRODUCT”. You put the link part that’s the same for all products into the redirection script (for most Sharesale datafeeds it’s “http://www.shareasale.com/m-pr.cfm?merchantID=SHAREASALEMERCHANTID&userID=YOURSHAREASALEID&productID=”) and the unique product ID into the link code.

It’s taken me years to pull these techniques together and you get it as part of Stallion, I would have paid thousands for these techniques 5+ years ago, they protect so much link benefit and make it harder for search engines to find and downgrade affiliate sites. Now all I need is to find the time to actually build affiliate sites :-)

David Law

David Law > AKA SEO Dave
*
: 20+ Years Experience as a Freelance SEO Consultant, WordPress SEO Expert, Internet Marketer, Developer of Multiple WordPress SEO Plugins/SEO Themes Including the Stallion Responsive Theme.

Website - SEO Gold