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

  1. Download the link-cloaking-plugin.zip file.
  2. Unzip the file.
  3. Upload the `link-cloaking-plugin` folder to the `/wp-content/plugins/` directory.
  4. Activate the plugin through the ‘Plugins’ menu in WordPress.
  5. (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 :

802 Responses to “Link Cloaking Plugin for WordPress”

  1. ubuntu tips says:

    sure, and thx..

    # BEGIN WordPress

    # Link Cloaker Plugin BEGIN

    RewriteEngine On
    RewriteRule out/([^/]*)/([0-9]+)/([0-9]+)/? http://example.com/wp-content/plugins/link-cloaking-plugin/wplc_redirector.php?post_id=$2&link_num=$3&cloaked_url=$0 [L]
    RewriteRule out/([^/]+)[/]? http://example.com/wp-content/plugins/link-cloaking-plugin/wplc_redirector.php?name=$1&cloaked_url=$0 [L]

    # Link Cloaker Plugin ENDS

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

  2. White Shadow says:

    Hmm, everything looks fine and the URLs are correct, but it still doesn’t work. Let’s try this : replace the plugin’s rules with these :

    RewriteEngine On
    RewriteRule out/([^/]*)/([0-9]+)/([0-9]+)/? /wp-content/plugins/link-cloaking-plugin/wplc_redirector.php?post_id=$2&link_num=$3&cloaked_url=$0 [L]
    RewriteRule out/([^/]+)[/]? /wp-content/plugins/link-cloaking-plugin/wplc_redirector.php?name=$1&cloaked_url=$0 [L]
    
  3. ubuntu tips says:

    Thx for your help.. my programmer is in now and he fixed it.. i’m not sure what he means, but I figured i’d post it here anyways in hopes you can make sense of it or it can help someone else… thx for your help earlier though, great plugin my man!

    —-
    in .htaccess before Link Cloaker rules was:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteRule ^to/(.*) http://$1 [R=301,L]

    So Link Cloaker rules didn’t work, I removed this.
    ——

  4. White Shadow says:

    Oh, if that code was before the cloaker’s rules then I’m not surprised the cloaker didn’t work. The above rules would intercept and process all URLs before the plugin would have a chance to do the redirect.

  5. Henry says:

    Hey, I want to add some instructions to the robots file to disallow the links which your plugin created. Whats the best way to do this?

  6. White Shadow says:

    May I suggest an alternative first : if you enable “Nofollow cloaked links” in plugin’s settings then search engines will treat them just as if they were disallowed in robots.txt.

    If you want to go the robots.txt route, something like this should work (replace “goto” with the cloaked link prefix you use on your site) :

    User-agent: *
    Disallow: /goto/
    
  7. henry says:

    Hey thanks for that. I feel kinda stupid….I had already checked the no follow box previously…

    This plugin is great though and excatly what I needed. Do you have plans to keep this updated? People like you are what WordPress is all about.

  8. White Shadow says:

    Well, I usually fix bugs as soon as possible, but new features are added rarely.

    Perhaps I should start selling this plugin (as in, for money), then I’d have a big incentive to keep improving it. Most other cloaking plugins are commercial already. I’m not quite sure users would appreciate a move like that 🙂

  9. Matt Price says:

    Hi,

    This is a great plugin and it works great for links within my posts but it does not seem to work for any other links. I have a template that has a modified single.php file that pulls a link from a custom field. Do you know if there is any way to get these links to be cloaked as well ?

    Thanks
    Matt

  10. Matt Price says:

    Just to add….

    This is the link that falls outside the “main post” within single.php

    ID, “custom_link”, true)): { ?>

    ID, $field_name, true); ?>
    <a href=””Check Latest Price

  11. Matt Price says:

    Whoops … that didn’t show properly.

    ID, “custom_link”, true)): { ?>

    ID, $field_name, true); ?>
    <a href=””Check Latest Price

  12. Matt Price says:

    Sorry… I am in danger of spamming these comments. (-: How do I add code to these comments ?

  13. White Shadow says:

    Use the <pre> tags when posting code. E.g. “<pre>…code…</pre>”

    That said, you can’t really cloak links outside posts. The feature has been suggested a few times before, but I still haven’t gotten around to implementing it.

    Edit : And it wouldn’t be as easy as just dropping a quick hack into the code. Unfortunately 🙂

  14. Matt Price says:

    Thanks anyway. I thought this might be the case after reading through other comments. I figured out how to incorporate the link within the post so problem solved. This is a fantastic tool. Many thanks

  15. Marco says:

    Hey White Shadow,
    thanks for the good work.

    I have one remark though. It seems your plugin doesnt work with wp Super Cache 🙁

  16. White Shadow says:

    Really? I’ve been using WP Super Cache on this site for months and so far the plugin seems to be working fine. E.g. the example link in the post above (“A Cloaked Link”) redirects correctly when I try to click it.

  17. Marco says:

    Could you paste your .htaccess? Do i have to put Linkcloak b4 or after Wp Super Cache?

  18. White Shadow says:

    It’s after WP Super Cache but before WP core rules in my .htaccess :

    # BEGIN WPSuperCache
    
    RewriteEngine On
    RewriteBase /
    AddDefaultCharset UTF-8
    RewriteCond %{REQUEST_URI} !^.*[^/]$
    RewriteCond %{REQUEST_URI} !^.*//.*$
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{QUERY_STRING} !.*=.*
    RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
    RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]
    
    RewriteCond %{REQUEST_URI} !^.*[^/]$
    RewriteCond %{REQUEST_URI} !^.*//.*$
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{QUERY_STRING} !.*=.*
    RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
    RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]
    
    
    # END WPSuperCache
    
    # BEGIN WordPress
    
    # 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
    
    
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    
    # END WordPress
    
  19. dmhf says:

    Thanks for your plugin. Unfortunately I’ve moved to a new host which doesn’t support mod_rewrite. Is there any chance that this plugin would work with a .htaccess file?

  20. White Shadow says:

    That would require pretty large changes in the plugin. I’ll add this to the list of possible improvements, but it’s unlikely to get implemented in the near future.

Leave a Reply