How does it work?
Step 1: Open the functions.php file of WordPress theme
Step 2: Add the following code at the bottom of functions.php
function show_ads_in_specific_country() {
$ip_address = $_SERVER[โREMOTE_ADDRโ];
$country_code = โPKโ; // Replace โPKโ with the country code for the country where you want to show the ad
$country = file_get_contents(โhttp://ip-api.com/json/$ip_addressโ);
$country = json_decode($country);
if ($country->countryCode == $country_code) {
// Display your ad code here
}
}
add_action(โwp_headโ, โshow_ads_in_specific_countryโ);
Note:
$country_code = โPKโ; here you can change the country code where you want to see the advertisement. (visitorโs country codes are available on ipapi.com or ipdata.co)
// Display your ad code here
This is the place where you put your advertisement code