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]<?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’;
}
?>[/php]
How to use?
Just find which element or part you want to disable in localhost testing and insert the code like this below.
[php]<?php
global $is_local;
if($is_local != ‘true’): //if not in localhost then show this ?>
<!– the disabled code will be here –>
<?php endif; ?>[/php]
Now when you are on localhost, the above wrap element will not be showed.