Patrick's Programming Blog

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:

http://www.ninjaforms.com/?ref=25

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:

http://www.shareasale.com/r.cfm?b=123456&u=654321&m=12345&urllink=&afftrack=

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:

http://speakinginbytes.com/out/ninjaforms/

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 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.

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's file editor

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

 

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}.

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.

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

Exit mobile version