Why and How You Should Cloak Your Affiliate Links the WordPress Way

Stormtrooper in a Cloak

If you've read this blog for a bit you'll know that I'm a big fan of Ninja Forms. Every couple of months I release a new extension which adds even more functionality to Ninja Forms and makes it even more powerful. What you might not know is that I'm also an affiliate. Every time someone follows one of my links to the Ninja Forms website and purchases something I get a small cut.

The way the affiliate system works is that I have a special link so the WP Ninjas know who referred the customer. Unfortunately, in most cases the links aren't intuitive, they're long, and sometimes they change which is a big pain to update. Instead of using the link as is you can cloak the link making it look like any other page on your site. Doing so makes it easier to read, they're easy to change, and there aren't any negative SEO affects on your site.

Best of all cloaking your links is actually easier than you think and can be done with just one WordPress plugin which you might already be using.

Why You Should Cloak Affiliate Links

There's a ton of reasons why you should cloak your affiliate links. The most important to me is how unreadable they are to humans. If you've spent all this time writing website copy you don't want them to see the link and be turned away since they don't know where they're going.

Affiliate Links Aren't Intuitive

Lucky for me Ninja Forms has a built in affiliate system which makes their links a bit prettier. My affiliate link looks like this:


Some sites use a 3rd party affiliate system and then the link looks awful. Genesis, a WordPress starter theme, has a pretty popular 3rd party affiliate system and your link might look like this:


If someone hovered over that link would they have any idea where they're going? If they're on the fence showing them an unknown domain won't help at all. They may think you're trying to trick them. Bye bye commission.

Instead of showing them an ugly wouldn't it be better to use a little web magic and show the user a pretty link which will be automatically redirected to the ugly link which will be redirected to the destination website. It's actually easier than it sounds and the result is pretty nice. My pretty affiliate link looks like this:


Isn't that much nicer? I like using the directory out for my affiliate links but you could use recommends or to or whatever you want. All of those inspire more confidence in the user.

Affiliate Links Are Advertisements and Should Be Treated as Such

It's one thing to link to a website to point someone to a resource. It's entirely different when you have a monetary incentive to place that link. That's why Google and other search engines treat affiliate links differently. You're technically suppose to put a rel=nofollow in each of your affiliate links.

But by cloaking your link you're not passing on pagerank (since you're linking to an internal page) and you don't need to nofollow your links. That's a whole step you don't have to take.

Affiliate Links Change

Links change. We all wish they would stay the exact same but that's unlikely. Companies & products grow and change so the domain may change, or the url structure to a specific product may change. Or maybe the company decides to go with a different affiliate system. Either way you should be prepared to change all of the links on your site at any point. By cloaking your links you don't need to change what your links look like you only need to change where they're being redirected to and that can be done in one place. This way you make one change and it affects all of the links on your site. Pretty cool huh?

How to Cloak Links Within WordPress

Hopefully by now you understand that there are plenty of good reasons to cloak your links. Now it's time to actually do it. Luckily it's pretty darn easy.

1. Install Redirection

Redirection Plugin

Redirection is available for free on WordPress.org

The first step is to install the Redirection plugin (free). I've used it for years when launching a new site to make sure all of the old links are redirected to their new pages but it can be used to cloak links just as easily.

2. Add Redirections

Under Tools->Redirection you can add new redirections. You'll need to enter your pretty link in the Source Url field. And you'll need to enter your affiliate link in the Target URL field.

Note: Redirection likes relative links. Instead of entering http://mysite.com/out/pretty-link/ just enter /out/pretty-link.

Redirection Settings

Enter your pretty link and affiliate link and Redirection does the rest

Now give it a test – your pretty link should redirect to your affiliate link just like that.

3. Hide Outbound Links in Robots.txt

There's one more step to make sure that robots don't index pages that don't actually exist. To do this you'll need to edit your robots.txt file. If you know how to do this manually go ahead and do so. I'm going to use a WordPress plugin to do it for me. Install WordPress SEO by Yoast.

Then click on the file editor.

WordPress SEO Edit Files

WordPress SEO's file editor

If you don't already have a robots.txt file you should create one

WordPress SEO Create Robots.txt


Now you'll want to edit your robots.txt file and prevent robots from visiting any of those cloaked links. You can do this with a Disallow: {your outbound directory}.

Robots.txt Disallow Out

Make sure you prevent robots from accessing your outbound links since they don't actually exist!

Hooray you're all done now! Go and make some affiliate links! If you have a ton of affiliate links I'm going to show you how to use a regular expression to dynamically create outbound links. A nice timesaver.

4. (Optional) Use Regular Expressions to Create Outbound Links

Now going back to my Ninja Forms example I currently have eight different extensions with eight different urls. I could manually copy in all eight links into Redirection but that's a bit of a pain. I'd rather use a pattern matching technology called regular expressions to automatically create the links for me. This way when I get new products I don't have to create new pretty links. They're already built. You don't need to know what regular expressions are you can copy my example.

Redirection Regular Expression

Using a regular expression to copy part of my pretty link and put it into my affiliate url

In this case I'm using this regular expression, ([A-Za-z0-9\+\.\-]*), to copy part of a url and put it in my affiliate url. The $1 is where the matched regular expression will be placed in the affiliate URL.

Pfew – alright that's the end of this massive blog post. Now go out and create some pretty affiliate links!

Photo Credit: JD Hancock

13 thoughts on “Why and How You Should Cloak Your Affiliate Links the WordPress Way

  1. Great post Patrick! I use a YOURLS install for my affiliate cloaking, but it’s the same essential process. I’d also add to this that you should always disclose affiliate links. In the US, the FTC pretty much requires this. Other countries’ regulations may vary, but I still think it’s the right thing to do even if it’s not required.

    Regarding PageRank/SEO… I’ve heard the argument that cloaked redirects don’t pass PageRank, but I’m not sure it’s true.

    Matt Cutts clearly states that PageRank is passed at the same level between 301s and regular links in this YouTube video from last year. Also, there’s a report here indicating that cloaked affiliate links (presumably w/o nofollow) got this guy penalised.

    Finally, there’s an important section at the bottom of this Google help doc that gives a bit more detail. It’s specifically referencing PPC, but I imagine Google views affiliate links similarly:

    Note that PPC (pay-per-click) advertising links that don’t pass PageRank to the buyer of the ad do not violate our guidelines. You can prevent PageRank from passing in several ways, such as:

    Adding a rel="nofollow" attribute to the anchor tag
    Redirecting the links to an intermediate page that is blocked from search engines with a robots.txt file


    To me, it looks pretty clear that unless you’re blocking your redirect link structure in robots.txt, you still need to nofollow the link to prevent PageRank from leaking through.

    • Hey Chris,

      Thanks for such a thoroughly researched comment! 🙂

      So if someone blocks the /out/ directory via their robots.txt file that should prevent the page rank from passing though?

    • Great topic! The author of the linked article mentions in the comments that his issue was just the sheer amount of links he had on the page that caused the issue, not necessarily cloaking, since he had nofollow on all the affiliate links already. Seems like Patrick’s got the right idea here by just blocking the “redirect” directory so it doesn’t get indexed and thus pageranked but I don’t think it really matters all that much in the grand scheme of SEO.

      SEO is a moving target for sure. I’d be very hesitant about putting more than a handful of affiliate links on a given page regardless of cloaking or nofollowing. The upper limit seems to be about 10 and even if you redirect to a nonexistent, cloaked link, google isn’t stupid.

      Think about what the algorithm is doing when it’s indexing… so this page has got a bunch of links that point to “nowhere” but actually redirect to known affiliate websites. Are they try to hide something from me? Technically the crawler shouldn’t crawl any url in /out/ but according to google that page may show up in the index if other people (or domains, like any social media) link to it (for example: a web scraper).

  2. […] Do you sell products as an affiliate or your site? Here’s a quick guide from Patrick Rauland on cloaking redirect links. […]

  3. Great stuff! Have been looking for a way to help monetise my blog, and this was really helpful. Cheers

  4. thank you so much for this awesome article! so many cloaking plugins are complicated and expensive but your solution using redirection and regular expressions is really easy and even free. cheers

  5. I have tried this on wordpress blog It’s working for me.
    But i have lossed what i am getting before.

    i.e I am using affiliate links like this – example.com/?affId=123&sid=[currentuser_id] (short code plugin) i am getting at the front with current logged in user id example for admin is – example.com/?affId=123&sid=1

    But after using this trick i have lossed it, at the front end i am getting mysite.com/out/example, but clicking on that link it will going directly – example.com/?affId=123&sid=currentuser_id

    Please help on this

    • Unfortunately Redirection doesn’t process shortcodes. You’d have to customize it. Or you could probably come up with a regular expression to print out the currentuser_id and then route it to the right place. I would work with a company like Codeable to help you with this. It should be a one off job that shouldn’t take much time.

  6. You said this in your post: I like using the directory out for my affiliate links.

    What do you mean by out as a directory? Why not make your cloaker link just http://moneysite.com/affiliate-link. I don’t understand why the out is in there.

    Hope you can help me get the answer. Thanks for the great post!

    • There’s nothing wrong with yoursite.com/affiliate-link. I like adding the extra directory to help people visually see that it’s an affiliate link. It also keeps them organized for me and I won’t accidentally ever create a page with the same url as an affiliate link.

      It’s your preference. 🙂

  7. How can I redirect without google knowing it. I would like google bots and spiders to see my original site while I redirect visitors to the redirect site. I don’t want to lose my rankings and be penalized by google for redirection.

    • I wouldn’t bother trying to hide things from Google. Search engines are going to do every thing they can to make sure that their users are finding the best content. They will follow links on your site so there isn’t anyway to hide that information from them.

      If you think it’s a good idea to redirect someone (for affiliate links for example) then do that. If google think that’s a bad idea it’s their prerogative to penalize you in their rankings.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.