Link Cloaking Plugin for WordPress
I’ve created a plugin for WordPress that can cloak outgoing links in your posts and/or pages (note : if you’d rather have a more general link cloaking tool, take a look at Link Manager).
Features
- Choose what to cloak - all links, only the links you specify or no links at all.
- Choose where to cloak - posts, pages or both.
- Configure the URL - you can set the “prefix” part of the URL (see examples below).
- Exception list - links pointing to domains in this list will not be cloaked. For example, this is useful if you have chosen to cloak all links but don’t want to cloak the links to your own domains.
- Compatible with all browsers - the link cloaker plugin doesn’t use JavaScript so it will work even for visitors that have disabled JS.
- “Smart” cloaking - relative, ambiguous or malformed URLs will not be cloaked. Better safe than sorry.
- Update : version 1.1 available - now with static link cloaking!
Examples
Here’s a link explicitly tagged for cloaking -
<a href="http://evil-guide.tripod.com/"><!--cloak-->A Cloaked Link</a>
And here’s what it looks like in the post - A Cloaked Link
If you have configured the plugin to cloak all links (the default) you don’t need the <!–cloak–> tag inside your links.
Installation
- Download the link-cloaking-plugin.zip file.
- Unzip the file.
- Upload the `link-cloaking-plugin` folder to the `/wp-content/plugins/` directory.
- Activate the plugin through the ‘Plugins’ menu in WordPress.
- (Optional) Go to Options -> Link Cloaking and modify the default settings to your liking.
- Go to Options -> Permalinks and click “Update Permalinks”. This ensures the plugin’s link redirection code is added to WordPress .htaccess file.
Download
Version 1.2.2 : link-cloaking-plugin.zip (9 KB)
Tested on WP 2.2 - 2.6.2.
mod_rewrite is required. If “fancy permalinks” work on your blog then you probably have this.
July 28th, 2007 at 4:56 pm
[...] I’ve created a plugin for WordPress that can cloak links in your blog posts and pages. Read more and download the plugin here. [...]
July 28th, 2007 at 8:00 pm
You mean link masking. I was thinking you had a search engine cloaking thingie going (showing different content or links to search engines)
Thanks
July 28th, 2007 at 8:12 pm
On internet marketing forums and similar sites this is often referred to as “cloaking” so I used that term here. There’s a whole bunch of related techniques, call them what you like - cloaking, masking, obfuscation.
I’ve heard about search engine cloaking but I haven’t really investigated that topic.
August 2nd, 2007 at 4:19 pm
Link Cloaking Plugin for WordPress…
This new plugin may be useful to anyone posting affiliate links on a blog. It can cloak either all or only selected links….
August 10th, 2007 at 6:22 am
Thanks for the plugin, i think it will work well on my blog for affiliate links
August 10th, 2007 at 6:11 pm
Thanks for the plugin. Is it possible to cloak links in the sidebar, for example I put an affiliate link in the blogroll?
August 10th, 2007 at 11:09 pm
Ramil - no, not yet. I’ll think about adding that feature. I’m not sure it’s possible/easy to do though because on most WordPress blogs the sidebar is handled by “widgets” which could be a problem.
If you have the link in question in a post you can copy & paste the cloaked link to the sidebar and it should work unless you add/remove links to the post with that link.
August 14th, 2007 at 12:10 am
Thank you for an excellent plugin and for making my life easier!
Jai
August 23rd, 2007 at 6:26 am
How can i get rid of the numbers at the end of the cloaked link? The post id and link id?
August 23rd, 2007 at 11:16 am
HiTech,
In this version you can’t get rid of them. They’re what allows me to keep the plugin simple and relatively fast.
To be able to ommit the numbers I’d have to either encode all of the original URL in the cloaked link (leading to long links with weird characters in them) or store the links in a database (meaning you’d need to set up every cloaked link manually). I’ll think about adding the second feature in a future version.
September 3rd, 2007 at 5:09 pm
Most affiliate links will not work becuase they are relative, ambiguous or malformed URLs
September 3rd, 2007 at 5:23 pm
Huh? That is simply not true.
Most affiliate links are not relative, as they point to a different site. They’re most likely unambiguous for the same reason. Malformed URLs probably wouldn’t work in most browsers, so if your links work, it’s likely they are well-formed.
From software perspective, affiliate links are no different from “ordinary” links.
September 4th, 2007 at 9:17 am
[...] cloaking in wordpress I found a goos Wordpress plugin for cloaking links here : Link Cloaking Plugin for WordPress | W-Shadow.com. It works great for me ! [...]
September 7th, 2007 at 10:49 pm
Sorry,
i thought they were not working because of all the characters but I missed a step in my installation
it actually works great
September 7th, 2007 at 11:11 pm
That’s okay, it’s good that you got it sorted out
September 8th, 2007 at 9:23 pm
[...] Cloak Affiliate Links - This plugin is necessary if you care about how your links look to visitors. Instead of displaying awful-looking affiliate links, like “http://wrdz72.notascam.buynow.com=?aff=12345“, this plugin will make your affiliate links look much more natural, readable, and non-threatening. It’s not perfect - the plugin does leave a couple numbers at the end (no big deal) - but it’s much nicer than the soup of letters and numbers most affiliate links resemble. [...]
September 19th, 2007 at 12:13 am
[...] time ago I created a WordPress plugin that can cloak affiliate links automatically. Today I’m releasing a new version, with all-new [...]
September 29th, 2007 at 3:48 pm
[...] Visit [...]
October 4th, 2007 at 5:59 pm
I just came across this and am playing with it, I love what I see so far, thank you :). There is one thing that I’d like to do, for affiliate links it’s a good idea to tag &afsrc=1 at the end of a cloaked link (to protect your commissions from being stolen from parasites and spyware).
I’m sure I could add that somewhere in the plugin files so that every link I cloak automatically gets that appended to the cloaked link. I just don’t have a clue how to do that though. Could you advise?
October 4th, 2007 at 6:01 pm
Just to clarify, when the &afsrc=1 is on the cloaked link, I mean that the link will be like this (using your example above):
http://w-shadow.com/goto/A_Cloaked_Link/45/4&afsrc=1
October 4th, 2007 at 7:12 pm
Hmm, doing that may be possible, but I don’t understand how would that help against spyware?
As for editing the files - if you’re familiar with PHP, you can take a look at the wplc_link_cloaking_plugin.php file, lines 87-90. This is where the final form of automatically cloaked links is determined. You could modify that, but then you’d need to also modify the URL rewriting rules on line 157 so that the links still work…
If you explain how it’s supposed to work and why &afsrc=1 is good against spyware, I may be able to implement the changes myself and send you the modified file.
October 10th, 2007 at 11:24 pm
First of all, great plugin! Thank you!
I’m trying to add NOFOLLOW tags to my cloaked affiliate links so the end result is:
Test
becomes
Test
Can you tell me which lines of the script I should replace, and with what?
Thank you again!
October 10th, 2007 at 11:55 pm
Just to clarify, the plugin is designed so that you can add the nofollow tag to the uncloaked link and it will stay there when it’s cloaked, too.
Now, for your question - the quick & dirty solution would be to replace line 90 (the one that starts with “return”) in the file wplc_link_cloaking_plugin.php with this line :
Try it out. I have a sneaking suspicion that this might cause conflicts with other link rewriting plugins (and similar), but it should work well enough in most cases.
October 11th, 2007 at 2:16 am
Hi White Shadow,
I found your plugin just a couple of days ago. After trying several other plugins/solutions to cloak my links…and failing to get them to work, imagine my excitement when I turned on your plugin and it worked right out of the box.
I LOVE it!
One question…
Do “hits” refer to actual clicks on those links or just page views?
Curtis Penner
October 11th, 2007 at 2:33 am
Hey, I’m glad you like it
“Hits” refer to the number of times a link has been followed, so you could say it’s pageviews… except the “real” pageview count is probably lower, because search engines and other bots would also be counted as “hits”.
Creating a reliable click stats report is nontrivial and I’m not aiming for that - the “Hits” figure is there to give a general idea about the link’s popularity only. You might want to find a separate plugin for accurate stats, or use Google Analytics. You can put the Analytics code on your blog with the Ultimate Google Analytics plugin (this is what I do on this blog).
October 14th, 2007 at 2:48 pm
[...] Cloak Affiliate Links Что умеет этот плагин: Заботитесь о виде своих [...]
October 22nd, 2007 at 1:00 am
Having problems with the 2.3 version of word press
it seems to be slowing down
Also it would not write to .ht access file
Does it have anything to do with file permissions
October 22nd, 2007 at 1:40 am
What do you mean “slowing down”? Anyway, it’s probably something to do with WP itself.
If Wordpress can write to .htaccess, so can the plugin, because it works from within WP. I assume you have tried updatibg permalinks, right?
November 1st, 2007 at 7:06 am
Hi.
Great plugin. However I am getting a 404 when I use it. Do you know how to fix it?
Thanks.
November 1st, 2007 at 2:31 pm
Do you mean you get a 404 when you click a cloaked link? If so, have you updated the permalinks?
November 2nd, 2007 at 11:02 am
Yeah, I updated permalinks.
November 2nd, 2007 at 2:11 pm
Well, I don’t have any other bright ideas then. Care to give me a specific example of a link that doesn’t work?
November 2nd, 2007 at 10:11 pm
a couple of things
i am noticing problems when using text link ads… specifically, the ads don’t work. I’ve tried updating the permalinks and everything, but when i click on a text link ad, it just hits an error page…
this could pose a big problem for people using TLA
second of all, i wish there was a way to cloak links on the blog roll….maybe not automatically, but manually in the wp-admin.. where for example, you can set ‘blogrolllink/aff?123″ to ‘mywebsite/blablabla’
November 2nd, 2007 at 10:27 pm
I don’t know about text link ads, but for the second idea - try going to Manage - Cloaked Links, this might be what you’re looking for.
I don’t have any TLA ads (at the moment) on this blog, so I really have no easy way to investigate this problem. Maybe, if you have “cloak all links” enabled, it might clash with TLA… try setting it to “selective cloaking” and see if it helps.
November 2nd, 2007 at 11:42 pm
text link ads provides users w/a wordpress plug-in so that they can sell context text links on their blog. So for example, an advertiser might pay you…oh i don’ t know, $4/mo (for example) for the word ‘cloaking’ in your post….
i’ve put link cloaker on selective cloaking for now
would it be too much work to create a drop down…or some sort of menu…in the link cloaker adminstration that lists all context links on a blog with a check box to let you cloak or uncloak? this way you don’t have to go through each post and manually cloak your links on ’selective cloaking…’
just a thought
November 3rd, 2007 at 12:05 am
It’s doable, but a lot of work. I’ll keep your suggestion in mind but I can’t promise anything.
November 3rd, 2007 at 4:20 am
i’m also getting a 404 error. I’ve updated the permalinks and htaccess accordingly.
my wordpress version is 2.3.1
Please help me with this a.s.a.p
Thanks!
November 3rd, 2007 at 4:24 am
visit my site and click on a link in a post and you’ll see.
November 3rd, 2007 at 1:58 pm
I looked at your site. I think the the problem is in the .htaccess. Where is your .htaccess located and what does it contain?
November 4th, 2007 at 12:19 am
i fixed the problem, the redirect.php file had to be in another folder called plugins within the orig. plugins directory. ex. plugins/plugins/redirect.php
one more question, after a cloaked link is clicked, is there a way to cloak the url on the address bar? is there a plugin or script that can do this?
a close example I can give are links on phazeddl.com and how .tk domains cloak site urls.
November 4th, 2007 at 1:44 am
It’s good to hear that you got it fixed, though it still is a bug - it shouldn’t require another folder.
I don’t know any WP plugins for cloaking the link in address bar, but I’ve seen various ways to do it in general. Frames (phazeddl.com uses an IFrame), JavaScript, etc. A quick Google search returns at least one free tool.
The easiest solution would be to modify wplc_redirector.php, remove the redirection code (the last 3 lines or so) and instead create a single frame that contains the target page. This should be easy for anyone who knows a bit of PHP/HTML, but you’re on your own here. I don’t intend to add this feature to the plugin.
November 10th, 2007 at 1:43 am
Can you please help on creating a frame code.
I don’t know how to insert the html code into the redirect php file
November 10th, 2007 at 2:02 am
Fine. Open wplc_redirector.php and go to the end of file. Delete all lines that start with “header….” and the line that says “exit()”. Then insert the below code after the “?>” -
That’s a very primitive version, but it should work. Not tested.
November 13th, 2007 at 6:37 am
Hello,
I get this error. Visit my site for an example.
Parse error: syntax error, unexpected ‘<’ in /home/halcyonr/public_html/3magin8/site/2/wp-content/plugins/plugins/wplc_redirector.php on line 39
This is the same problem I had before when I tried to do it myself. How do you insert an html code into a php file?
Thanks!
November 13th, 2007 at 12:41 pm
PHP code is between “<?php” and “?>”, everything outside these separators will be treated as HTML. You should be OK inserting HTML after the last “?>” in the file. It is also possible to output HTML (or something else) from PHP code by using the echo function.
November 15th, 2007 at 6:43 pm
Awesome plugin! Just what I’ve been looking for
Is it possible to tell the plugin to encode not only the post content but also a custom tag?
e.g. for ach of my blog posts I have a custom tag called ‘deeplink’ - how can I get the plugin to cloak this?
November 15th, 2007 at 7:34 pm
If the tag is added by another plugin and shows up inside the post when the post is displayed, you can’t really cloak it (at least not without some changes to the cloaking plugin… which might lead to new bugs).
Arrgh, I need more information to really answer your question
Is this tag part of the post or do you enter it in an additional field on the ‘Write Post’ screen? Also, if it’s added by a plugin, which plugin? It would be easier if I could look at the source code.
November 15th, 2007 at 7:57 pm
Hey, thanks for your quick response.
Yes, its one of the additional tags that you enter as part of the Write screen.
I am able to reference it in my templates using:
ID, “deeplink”, true); ?>
November 15th, 2007 at 8:14 pm
Looks like your code example got messed up; you should wrap it in <pre lang=”php”> … </pre> tags for it to display correctly (you even get syntax highlighting then).
Anyway, since you use it in your templates, there is no other way to cloak the links than to modify both the template code and the cloaking plugin. It’s complex, but doable if you’re sufficiently familiar with PHP and WordPress. I can give you a few hints on what to look for, but you’d be largely on your own.
November 15th, 2007 at 8:33 pm
This is the code I use to reference the custom field in my templates.
ID, “Thumbnail”, true); ?>
Any tips would be much appreciated!
November 15th, 2007 at 8:34 pm
php echo get_post_meta($post->ID, "deeplink", true);
November 15th, 2007 at 9:31 pm
Hmm, is <pre> not allowed in normal comments? (It works for me, but then I’m the admin of this blog).
Okay, there are two things you need to do - rewrite the “deeplink” so that it’s cloaked and modify wplc_redirector.php so that it can recognize the links.
Rewriting the link : I’d replace your template code with something like this -
You can put something else in place of the “deeplink” text there, like “info”, “details” or whatever you want. This will create an URL that has the same pattern as other cloaked links, yet can be recognized and treated differently because it ends with a zero (normal cloaked links end with above zero numbers). This code should also gracefully handle the situation when the plugin is no longer active, falling back to uncloaked links.
Modifying the redirector : you’ll need to edit wplc_redirector.php for this, adding special handling for links that end with zero. This can be done in several ways… Look at the first if block, find code that looks like this -
I’d do it like this -
Well, that’s all. Unless I’ve forgotten something, or made some typos there (possible, didn’t check), it should work.
November 16th, 2007 at 11:55 am
That worked a treat!
I owe you a beer
December 8th, 2007 at 5:44 am
[...] Link Cloaking - Protect your affiliate links. This plug-in allows you cloak (hide) outgoing links in your posts and/or pages [...]
December 14th, 2007 at 5:18 pm
[...] can check this post for more [...]
December 18th, 2007 at 12:18 am
ok, I’ve installed the plugin, and it seems to be working. yay! thanks for the work on this.
What I’d like to know is why your example on link cloaking, ie the how to be evil site, which is promoting a book, doesn’t have the amazon link cloaked to something that looks way nicer?…
oh, and could you possibly, in your copious spare time, do a single site step by step walkthrough? for all us noobs to the wonderful world of WordPress?…
thanks for the work!
December 18th, 2007 at 12:45 am
That site isn’t mine, it’s just a random site that I found one day and liked enough to use it as an example here
I’m in no way affiliated with that website.
What do you mean with “a single site walkthrough”? Cloaking links on a site that isn’t running on WordPress? Or something else?
December 23rd, 2007 at 8:05 pm
Thanks again for the help!
Happy Holidays!
January 4th, 2008 at 2:28 am
I keep getting a 404 page. This is the page - http://www.smartgeezer.co.uk/2008/rip-curl-hells-bells-reversible-beanie-hat/ - permalinks has been updated, htaccess updated, I’m pretty sure I set it up right.
Also, the link doesn’t open in a new window, even if I add the relevant code to Line 90.
Any ideas?
January 4th, 2008 at 2:41 am
OK, I’ve fixed the opening in a new window (had to remove nofollow in the Link Cloaking options) but not the actual link. It just tries to open the link - http://www.smartgeezer.co.uk/goto/link/68/1 - rather than converting it to the proper cloaked link.
January 4th, 2008 at 3:04 am
I’ve looked at your site and my guess is that the .htaccess rules aren’t working. Can you post the relevant part of your .htaccess here? Anything between “# Link Cloaker Plugin BEGIN” and “# Link Cloaker Plugin ENDS”.
Alternatively, email it to me at whiteshadow {at} w-shadow (dott) com
January 4th, 2008 at 11:38 am
# Link Cloaker Plugin BEGIN
RewriteEngine On
RewriteRule goto/([^/]*)/([0-9]+)/([0-9]+)/? wp-content/plugins/link-cloaking-plugin/wplc_redirector.php?post_id=$2&link_num=$3&cloaked_url=$0 [L]
RewriteRule goto/([^/]+)[/]? wp-content/plugins/link-cloaking-plugin/wplc_redirector.php?name=$1&cloaked_url=$0 [L]
# Link Cloaker Plugin ENDS
tx
January 4th, 2008 at 12:43 pm
Interesting. The .htaccess looks fine. What’s more, the redirector script itself works OK, as can be verified by visiting this link :
http://www.smartgeezer.co.uk/wp-content/plugins/link-cloaking-plugin/wplc_redirector.php?post_id=68&link_num=3
Maybe the rewriting rules don’t get executed. Is that part of .htaccess before or after lines that look like this? -
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]January 4th, 2008 at 9:17 pm
The whole .htaccess which sits in the root:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^smartgeezer.co.uk [NC]
RewriteRule ^(.*)$ http://www.smartgeezer.co.uk/1 [L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# Link Cloaker Plugin BEGIN
RewriteEngine On
RewriteRule goto/([^/]*)/([0-9]+)/([0-9]+)/? wp-content/plugins/link-cloaking-plugin/wplc_redirector.php?post_id=$2&link_num=$3&cloaked_url=$0 [L]
RewriteRule goto/([^/]+)[/]? wp-content/plugins/link-cloaking-plugin/wplc_redirector.php?name=$1&cloaked_url=$0 [L]
# Link Cloaker Plugin ENDS
January 4th, 2008 at 9:19 pm
You beauty! You’re right, I moved the Link Cloaker stuff to the top and now it works.
Thanks a lot for your help and for this plugin.
January 4th, 2008 at 9:25 pm
Good
January 8th, 2008 at 7:24 am
I’ve spend some time reading this article and I have to congratulate you for creating a WP plugin that’s doing this.
I’ve wrote a small article dedicated to easy cloaking methods using JavaScript and PHP for others that are not so good with programming
Link cloaking step by step guide
January 8th, 2008 at 6:19 pm
Fantastic plugin mate,
Thank you for releasing it!!!
Have a Great 2008
January 14th, 2008 at 10:43 pm
Hi, i wanted to use your plugin also. i uploaded it to the plugin directory, then, i activated it and updated the permalinks! but it doesn’t write any code in the htaccess file, so it doesn’t work!
can you help me? any idea?
January 14th, 2008 at 10:50 pm
do i maybe have to change something in the server admin menü?
January 14th, 2008 at 10:53 pm
I wouldn’t know about your server admin menus, but maybe you could try adding the code manually and see if it works? In most cases adding this to .htaccess should work :
The above code should probably be placed *above* any code that is already there.
January 14th, 2008 at 10:58 pm
doesn’t work
my version of wordpress is 2.3.1 as i think.
hmm… any other idea?
my htaccess now looks like this:
# .htaccess file create by vsa 3.2.9 webserver_rev 2.3
AuthType Basic
AuthName “Members Only”
AuthUserFile /vol2/home/k102184web/.htusers
AuthGroupFile /vol2/home/k102184web/.htgroups
# Link Cloaker Plugin BEGIN
RewriteRule more/([^/]*)/([0-9]+)/([0-9]+)/? wp-content/plugins/link-cloaking-plugin/wplc_redirector.php?post_id=$2&link_num=$3&cloaked_url=$0 [L]
RewriteRule more/([^/]+)[/]? wp-content/plugins/link-cloaking-plugin/wplc_redirector.php?name=$1&cloaked_url=$0 [L]
# Link Cloaker Plugin ENDS
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
January 14th, 2008 at 11:14 pm
Eh, I forgot to mention to put your own option instead of “more” there; I think it’s “goto” by default.
Other than that, I’d check if the scripts are there (yourdomain.com/wp-content/plugins/link-cloaking-plugin/) and if the redirector is actually getting called (check HTTP headers or something, if you know how).
January 14th, 2008 at 11:21 pm
I changed it to goto, but nothing happened! hmm… how can i check, if the redirector is called? ^^ i’m not such a pro
January 14th, 2008 at 11:31 pm
Well, a simple way would be to open wplc_redirector.php in a text editor and put something - anything - before the first “<?” string. Then click a cloaked link and see if the text you placed there shows up.
January 14th, 2008 at 11:42 pm
i put “roflmao :D” before the first <?php and it appeard in the left corner of the whole website including the admin menu
January 14th, 2008 at 11:56 pm
I find that unlikely/strange. wplc_redirector.php should only be called when you click a cloaked link. Maybe you modified wplc_link_cloaking_plugin.php?
January 15th, 2008 at 12:00 am
oh
you’re right
i modified the wrong file! ;D;D
but if i put it into the redirector.php file, nothing happens if i click on a cloaked link… he always says, that this page doenst exist oO
January 15th, 2008 at 12:15 am
I think the .htaccess is to blame, because it doesn’t call the redirector… and that’s all I can say
If I was in a situation like this I would try to mess around with the .htaccess file, trying various things, to see why it doesn’t work. However, I don’t have a tutorial for that…
January 24th, 2008 at 6:24 pm
I met same problem with Christoph…:-0, hope I can find the solution soon….