• 0

Switch between multiple menu's when localization is changed


Question

Posted · Report post

Hi there, my first post on these forums!

 

I use pagelines framework and want to know how to change a menu based on the current localization of wordpress.

I use a plugin (Bogo) that switches between 3 languages: Dutch, English and French.

( define('WPLANG', 'nl_NL') -> define('WPLANG', 'en_US'); )

 

 

I also added 3 menu's: NLmenu, ENGmenu and FRmenu which stores the pages that links to the corresponding language page (/home/,  /en/home, /fr/home/..)

 

How can I change the menu that's displaying in the navbar section (not fixed) when the localization changes?

 

Here is the code I have so far in the base theme's functions.php:

// Register Menus
add_action( 'init', 'asgro_register_additional_menus', 11 );

function asgro_register_additional_menus() {
	register_nav_menu( 'NLmenu', _x( 'NL menu', 'navbar_brand', 'pagelines' ) );
	register_nav_menu( 'ENGmenu', _x( 'ENG menu', 'navbar_brand', 'pagelines') );
	register_nav_menu( 'FRmenu', _x( 'FR menu', 'navbar_brand', 'pagelines') );
}

add_filter( 'wp_nav_menu_args', 'asgro_nav_menu_args' );

function asgro_nav_menu_args( $args ) {
	$locale = get_locale();

	if ( 'nl_NL' == $locale )
		$args['theme_location'] = 'NLmenu';
	if ( 'en_US' == $locale )
		$args['theme_location'] = 'ENGmenu';
	if ( 'fr_FR' == $locale )
		$args['theme_location'] = 'FRmenu';

	return $args;
}
// END Register Menus

Thanks in advance

 

Share this post


Link to post
Share on other sites

3 answers to this question

  • 0

Posted · Report post

Our developer will look at this on Monday.  Thanks for your patience.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

I found a way that is not the correct thing to do (especially for SEO). But it gets the job done.

 

Adding all the pages of all different languages in the main-menu.

Adding classes to the menu items corresponding to the menu language; So Home > Css class: nl-menu, Accueuil (French for home) > Css class: fr-menu etc..

Then I used display: none in css to hide the menu items that don't correspond with the language:

body.nl-NL li.eng-menu, body.nl-NL li.fr-menu {
    display: none;
}
body.en-US li.nl-menu, body.en-US li.fr-menu {
    display: none;
}
body.fr-FR li.nl-menu, body.fr-FR li.eng-menu {
    display: none;
}

But please developer, can you assist me in making this possible with PHP?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

bartslot,   the way you've done it should not be a problem for SEO.

 

There are plugins that would allow you to maintain multiple installations and auto-detect the language.   So, someone on a computer set with French as its base language would automatically redirect to the French installation.

 

That's the way most large company sites do it, as I recall.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now