$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>custom field - How to make menu country specific?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

custom field - How to make menu country specific?

matteradmin11PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

Is 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';
}
Post a comment

comment list (0)

  1. No comments so far