Sometime when you are working with XAMPP or MAMPP on localhost, you want to exclude or disable certain element or part if you are not working in live site environment.

A javacript like tracking code, google analytic code or adsense custom channel code should not be run in localhost testing environment. This may lead to devastating outcome especially with adsense code.

Here’s a easy and simple snippets you can add into your testing site php or WordPress functions.php.

<?php
//////////////////////////////////////////////////////////////////////////////
// check if local testing is active
/////////////////////////////////////////////////////////////////////////////
global $is_local;
$whitelist = '127.0.0.1';
if( $_SERVER["REMOTE_ADDR"] == $whitelist){
$is_local = 'true';
} else {
$is_local = 'false';
}
?>

How to use?

Just find which element or part you want to disable in localhost testing and insert the code like this below.

<?php 
global $is_local; 
if($is_local != 'true'): //if not in localhost then show this ?>

<!-- the disabled code will be here -->

<?php endif; ?>

Now when you are on localhost, the above wrap element will not be showed.

Related Articles:

Snippets
How to Use New Facebook API 2.7 for Fan Page and Post Share Count
Snippets
How To Fix Chinese Language WordPress Excerpts Issue
Snippets
How to Get Facebook Page Like Count Without Access Token