I’m glad you found that useful.
For this to work, you would first need to add as many menus as you need in your theme’s functions.php file. The wp_register_menus article I shared above covers this part. Make sure to backup the file first and to check whether your theme doesn’t already support menus before you make any changes to it.
Then, as you well put it, you would have to include the new menus by editing your theme’s header.php file and inserting a conditional php statement so that only the country-relevant menu is displayed. If you use the premium plugin above, your code would look smth like this:
<?php
// Checks if plugin function exists.
if (function_exists('isCountryInFilter')) {
// If it does, checks if visitor's location is the US.
if( isCountryInFilter(array("us")) ) {
// If it is, displays menu for US.
wp_nav_menu( array('menu' => 'US Menu') );
}
// If location is not the US, checks if visitor's location is Mexico.
elseif( isCountryInFilter(array("mx")) ) {
// If it is, displays menu for Mexico.
wp_nav_menu( array('menu' => 'Mexico Menu') );
// If location is either US or Mexico,
} else {
// Displays a default menu
wp_nav_menu( array('menu' => 'Default Menu') );
}
}
?>
If you only want to have US and Mexico menus and not fallback default menu, simply delete this line:
wp_nav_menu( array('menu' => 'Default Menu') );
Lines that start with //
are for explanation purposes only and don’t have any effect on the actual code.