How to create redirect all external links in wordpress


Last modified: March 22, 2014

If you are running a affiliate website and you want to cloaking and redirecting all external links in your website ? So in this tutorial we will show you How to create redirect all external links in WordPress.


Example external link:

Url alias to redirect to an outside site:

Now following the instructions bellow:

Step 1: Download this file: javascript.js (225 downloads) . Open it and change this line to your address

a_to_ve[i].href = "" + a_to_vi;


a_to_ve[i].href = "" + a_to_vi;

Step 2: put this code in your file “footer.php” of your theme

    //link to this js file you have downloaded above
    <script src="" type="text/javascript"></script>
    <script type="text/javascript">
    //name of the sites that you want to exclude. only the name.
    protected_links = "myspace,ebay";
    <!--script at the end of the body-->

Step 3 : Finally, create a file called “redirect.php” in your root directory with the code:

//get the link
$str = $_GET['url'];

if ($str == '') {
//if the variable URL link is empty. eg ".../redirect.php?url=" or ".../redirect.php" then redirects to home.
} else {
//otherwise redirects the external site.
header('Location: '.$str);

Done !

If you have any problem, Please use comment box bellow !


About Author

I'm a freelance with over 3 years experience working in PHP with CMS Wordpress and design website layout. In my spare time, I go fishing, lean internet marketing, scout new blogging strategies,free Xbox live gold codes and techniques, and work from wherever. View me on: Google+ | Facebook.

Leave A Reply