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.
January 26th, 2008 at 4:49 pm
a BIG fat thanks for this plug!!
Was going nuts because I had only 404s in the beginning, but found the solution in the comments here - maybe you can add it to the readme that the code in .htaccess has to be at the top - by default it is added in between and wordpress (2.3.2 on my site) adds the WP defaults to the end of the file again… so editing .htaccess manually seems to be a must.
Now just have to manually redirect the sidebar links.
All best and again THANKS for this one!
January 24th, 2008 at 6:24 pm
I met same problem with Christoph…:-0, hope I can find the solution soon….
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 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 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 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: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: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: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 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 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:50 pm
do i maybe have to change something in the server admin menü?
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 8th, 2008 at 6:19 pm
Fantastic plugin mate,
Thank you for releasing it!!!
Have a Great 2008
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 4th, 2008 at 9:25 pm
Good
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: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 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 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 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 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 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?
December 23rd, 2007 at 8:05 pm
Thanks again for the help!
Happy Holidays!
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 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 14th, 2007 at 5:18 pm
[...] can check this post for more [...]
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 [...]
November 16th, 2007 at 11:55 am
That worked a treat!
I owe you a beer
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.