Link Cloaking Plugin for WordPress
This is a plugin for WordPress that can automatically cloak outgoing links in your posts and/or pages.
Download plugin
(Note: May not be compatible with the latest version of Eclipse Link Cloaker.)
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.
- 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.
- If desired, you can also add your own cloaked links manually.
Examples
Lets say you’ve got a link you want to be cloaked.
<a href="http://example.com/?affiliate=me">Cloak Me</a>
Once you install the plugin, it will automatically, without requiring any configuration, turn it into a cloaked link when it’s displayed to a visitor:
<a href="http://yoursite.com/goto/Cloak_Me/12/34">Cloak Me</a>
Here’s a live example: Cloak Me
As an alternative to the fully automatic cloaking, you can switch the plugin to “selective cloaking” and tag the links you want to cloak manually:
<a href="http://example.com/?affiliate=me">Cloak Me<!--cloak--></a>
Note: The plugin does not actually edit your posts or permanently modify your links. Instead, it switches them on-the-fly whenever someone views them on your site. When editing a post in the admin panel, you will see the original, uncloaked link.
Download
Version 1.8.4 : link-cloaking-plugin.zip (16 KB)
Requirements :
- WordPress 2.8 – 3.3
mod_rewrite
. If “pretty permalinks” work on your blog then you probably have this already.
(Note: May not be compatible with the latest version of Eclipse Link Cloaker.)
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 Settings -> Link Cloaking and modify the default settings to your liking.
FAQ
Why are some of my links not getting cloaked?
The most common possibilities are:
- Links in the sidebar, header, comment area and so on can’t be cloaked by the free version of the plugin. It only works on links in page/post body. Upgrade to the premium version to cloak links anywhere on the page.
- Links added using other plugins, theme features or custom fields are also supported only in the premium version.
- JavaScript links, as well as Flash and context-sensitive ads are not supported by any version of this plugin.
Why are none of my links getting cloaked?
- If using “Seletive cloaking”, make sure you have actually marked some links with the
<!--cloak-->
tag. - Double-check that the links in question aren’t added or modified by plugins, the theme, or custom fields.
- Contact me. You might have found a bug.
The exception list doesn’t seem to work. What could be the problem?
Make sure to enter only domain names in the “Exceptions” box. For example, given a link like “http://example.com/directory/page.html”, the domain name is the “example.com” part. So to prevent the plugin from cloaking that link, add “example.com” (sans quotes) to the “Exceptions” box. Entering the full URL or “http://example.com/” will not work.
Additionally, if some of your links point to example.com and some to www.example.com, you will need to add both of those to the exceptions.
Why do some cloaked links redirect me back to my homepage?
Most likely, your post(s) contain links created or modified by other plugins, the theme, or custom fields. Either remove those links, or upgrade to the premium version.
Why do some cloaked links redirect me back to my homepage?
See the previous question.
Why do cloaked links display a “Not Found” error?
- Make sure you’re using pretty permalinks.
- Your .htaccess might be out of date. To update it, go to Settings -> Permalinks and click “Save Changes”.
- Your hosting company may be blocking browser access to PHP files in the /wp-content/plugins/ directory, usually as a security measure. The free version of the plugin is not compatible with these hosts. Consider using the premium version instead.
I have a question not addressed in this FAQ. What should I do?
Either leave a comment below, or email me directly. My email address can be found on the contact page.
Related posts :
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!
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.
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?
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.
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); ?>
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
[…] 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? –
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