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

  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 Options -> Link Cloaking and modify the default settings to your liking.
  6. 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.

Related posts :

201 Responses to “Link Cloaking Plugin for WordPress”

Pages: « 7 6 5 4 [3] 2 1 » Show All

  1. 81
    BrainWaver Says:

    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!

  2. 80
    Jay Says:

    I met same problem with Christoph…:-0, hope I can find the solution soon….

  3. 79
    White Shadow Says:

    I think the .htaccess is to blame, because it doesn’t call the redirector… and that’s all I can say :P 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…

  4. 78
    Christoph Says:

    oh :D you’re right :D 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

  5. 77
    White Shadow Says:

    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?

  6. 76
    Christoph Says:

    i put “roflmao :D” before the first <?php and it appeard in the left corner of the whole website including the admin menu

  7. 75
    White Shadow Says:

    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.

  8. 74
    Christoph Says:

    I changed it to goto, but nothing happened! hmm… how can i check, if the redirector is called? ^^ i’m not such a pro :P

  9. 73
    White Shadow Says:

    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).

  10. 72
    Christoph Says:

    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

  11. 71
    White Shadow Says:

    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 :

    # 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
    

    The above code should probably be placed *above* any code that is already there.

  12. 70
    Christoph Says:

    do i maybe have to change something in the server admin menü?

  13. 69
    Christoph Says:

    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?

  14. 68
    learn japanese online Says:

    Fantastic plugin mate,

    Thank you for releasing it!!!

    Have a Great 2008

  15. 67
    RichBeaver Says:

    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

  16. 66
    White Shadow Says:

    Good :)

  17. 65
    Ben Says:

    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.

  18. 64
    Ben Says:

    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

  19. 63
    White Shadow Says:

    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]
  20. 62
    Ben Says:

    # 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

  21. 61
    White Shadow Says:

    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

  22. 60
    Ben Says:

    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.

  23. 59
    Ben Says:

    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?

  24. 58
    cloudstrif3 Says:

    Thanks again for the help!
    Happy Holidays!

  25. 57
    White Shadow Says:

    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?

  26. 56
    bonafide Says:

    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!

  27. 55
    3 Easy Ways To Cloak Affiliate Links And Thereby Earn Two Fold | Blogging Tune Says:

    [...] can check this post for more [...]

  28. 54
    Wild Cash Flow » Blog Archive » 12 Useful WordPress Plug-ins You Must Have Says:

    [...] Link Cloaking - Protect your affiliate links. This plug-in allows you cloak (hide) outgoing links in your posts and/or pages [...]

  29. 53
    Chris Says:

    That worked a treat!

    I owe you a beer

  30. 52
    White Shadow Says:

    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 -

    $url = get_post_meta($post->ID, "deeplink", true);
    if (isset($ws_link_cloaker)) {
    	$url = get_option('siteurl').'/'.$ws_link_cloaker->options['prefix'].
    			'/deeplink/'.($post->ID)."/0";
    }
    echo $url;

    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 -

    $link_count=preg_match_all($wplc_url_pattern, $this_post->post_content, 
    	$matches, PREG_SET_ORDER);
     
    if($link_count >= $link_num){
    	$url = $matches[$link_num-1][2];
    	$url = str_replace('&amp;','&',$url);
    } else {
    	$url = get_option('siteurl');
    }

    I’d do it like this -

    if (0 == $link_num) {
    	$url = get_post_meta($post_id, "deeplink", true);
    } else {
    	$link_count=preg_match_all($wplc_url_pattern, 
    			$this_post->post_content, 
    			$matches, PREG_SET_ORDER);
     
    	if($link_count >= $link_num){
    		$url = $matches[$link_num-1][2];
    		$url = str_replace('&amp;','&',$url);
    	} else {
    		$url = get_option('siteurl');
    	}
    }

    Well, that’s all. Unless I’ve forgotten something, or made some typos there (possible, didn’t check), it should work.

Pages: « 7 6 5 4 [3] 2 1 » Show All

Leave a Reply