This topic is now archived and is closed to further replies.

Switch between multiple menu's when localization is changed

4 posts in this topic

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

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

Share this post

Link to post
Share on other sites

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: li.eng-menu, {
    display: none;
body.en-US, body.en-US {
    display: none;
}, 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

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

  • Similar Content

    • Wordpress menus scrambled & disappear
      By JawDesigns+
      Hi everyone,
      I was hoping someone could help. Firstly all my websites are DMS and all hosted on Flywheel. Recently I have noticed that on my sites including fresh installs with only DMS and a few DMS sections the main wordpress menus are disappearing when I hover them in the dashboard. This looks really flakey and I am not sure why. I have tried disabling the plugins but this does not help me.
      Please see screen grab. Has anyone seen this?
      Thanks, James

    • Child DMS theme localization problem
      By Plev
      I have child theme where i use "my-text-domain" then following wordpress codex steps to localize child theme do not work ( I have my .pot file as well with .po and .mo files in folder 'languages' of my DMS child theme) I tried both ways to register text domain (load_theme_textdomain and load_child_theme_textdomain) unfortunatelly non of them worked for me, any suggestions? Maybe there is some connection with unsolved issue with translation of main DMS theme from child theme posted on February which is still not solved. 
      Looking forward for any help,
      thx in advance.
    • Sub menus not working..
      By create
      I have a problem with sub menus with my main nav. I basically have a top-level nav called 'products' and custom sub heading called 'Everyday' with a sub menu from that, but for some reason - its not working.
      I can't understand why, it should be seamless *or* is there something within the framework that prevents this?
      See the attached screenshots showing how the menu is structured and should be (back-end) and what its doing front end.
      Grateful for any pointers
    • I really do need some help!
      By PeterBuilt
      I posted two different questions earlier, and I am having a lot of trouble with DMS 2.
      Every time I make a change to one page absed on a specific DMS 2-template the rest of my website is affected, some loses all styling, some loses sections.
      I am using Polylang for translations. For this I have made a number of custom menus in different languages.
      When I try to make the English version use the English menu all the other language pages are set to use the english menu.
      This is no good - I am really frustrated.
      I am almost sure part of the blame falls on me - I must be doing something wrong.
      Can you please help me out - thanks.
    • Custom menus
      By PeterBuilt
      Hi Pagelines support,
      I have a client who wants to have an fairly high number of landing pages, (product pages), each with a separate unique menu.
      He wants at least 40-50 of such pages each with a separate menu assigned.
      Can that high a number of menus be assigned in DMS 2?
      Do you have an idea on how to achieve this?
      thank you
      best regards