Link Cloaking Plugin for WordPress
I’ve created a plugin for WordPress that can cloak outgoing links in your posts and/or pages.
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.
- As of version 1.1, static link cloaking.
New! The premium version of this plugin is now available and includes several new features :
- Cloak links in any part of your site, including the comment section and the sidebar.
- Five new cloaking types – for example, you can display the cloaked URL in a frame, or use a special redirect that hides the referrer.
- Improved link management and click statistics.
- Free automatic updates.
- And more. Check out EclipseCloaker.com for complete details.
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.
- Re-save your permalink settings to insert the plugin’s link redirection code to the WordPress .htaccess file :
- WP 2.7 and above : Go to Settings -> Permalinks and click “Save Changes”.
- Older versions of WP : Go to Options -> Permalinks and click “Update Permalinks”.
Download
Version 1.3 : link-cloaking-plugin.zip (9 KB)
Requirements :
- WordPress 2.2 – 2.8.4
mod_rewrite. If “pretty permalinks” work on your blog then you probably have this already.
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.
This is the code I use to reference the custom field in my templates.
ID, “Thumbnail”, true); ?>
Any tips would be much appreciated!
php echo get_post_meta($post->ID, "deeplink", true);
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.
That worked a treat!
I owe you a beer
[...] Link Cloaking – Protect your affiliate links. This plug-in allows you cloak (hide) outgoing links in your posts and/or pages [...]
[...] can check this post for more [...]
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!
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?
Thanks again for the help!
Happy Holidays!
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?
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.
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
# 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
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]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
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.
Good
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
Fantastic plugin mate,
Thank you for releasing it!!!
Have a Great 2008
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?
do i maybe have to change something in the server admin menü?
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.
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
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).
I changed it to goto, but nothing happened! hmm… how can i check, if the redirector is called? ^^ i’m not such a pro
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.
i put “roflmao
” before the first <?php and it appeard in the left corner of the whole website including the admin menu
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?
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