How to make WordPress menu country specific? Like I want to show one menu for only one country and hide it from rest of all. Don't want to purchase a plugin. How to do it with code customization?
How to make WordPress menu country specific? Like I want to show one menu for only one country and hide it from rest of all. Don't want to purchase a plugin. How to do it with code customization?
Share Improve this question asked Feb 19, 2019 at 7:18 abhi25abhi25 12 bronze badges 1- Obtain a Geolocation database. For each request, extract the IP address, look up the country in the Geolocation database and, based on that, hide/display menu items. Doable, but not trivial. – Jos Commented Feb 19, 2019 at 9:51
1 Answer
Reset to default 0Is there a way to tell which country you are in when viewing the site? I mean like is the domain name example.uk | example.ca | example/en ... That kinda thing?
Then you could search your domain for the string for that country:
$protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://';
$url = $protocol . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if (strpos($url,'/en/') !== false) {
echo 'English version';
} else if (strpos($url,'/us/') !== false) {
echo 'US version';
} else {
echo 'Not UK or US Version';
}