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.

// check if local testing is active
global $is_local;
$whitelist = '';
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.

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:

How to Get Facebook Page Like Count Without Access Token
WordPress Tutorials
WordPress Developer should learn about apply_filters() and why?
Different Post Count in WordPress Search and Archive Page
Using Searchform to Search Keyword on WordPress Title only