When I make my WordPress single site become a multilingual site using qTranslate plugin, everything seems fine to me. I can easily translate almost anything with a simple tag, including translating the menu. However, there is time when I need something more than changing the 'Navigation Label' for each language. For example, through one of the menu links, I want to point my WordPress site on example.com to johndoe.com, and when I switch it to the second language, it will point my site from example.com/id to johndoe.co.id. I have to set different menu for it.
Here is how I achieve it:
- Create first menu on Appearance > Menus. For this tutorial, let's name it "Menu 1 en". This will be shown on site's English version.
- Then create second menu, say its name is "Menu 2 id". This will be shown on site's Indonesian version.
- Edit header.php of your theme "Twenty Twelve" or its child theme you're using. You can use built-in editor on WordPress (Themes > Editor) or other text editor.
- Find and replace this:
wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) )
with:
if ( qtrans_getLanguage() == 'en' ) { wp_nav_menu( array('menu' => 'Menu 1 en', 'theme_location' => 'primary', 'menu_class' => 'nav-menu') ); } if ( qtrans_getLanguage() == 'id' ) { wp_nav_menu( array('menu' => 'Menu 2 id', 'theme_location' => 'primary', 'menu_class' => 'nav-menu') ); }
Note that 'en' and 'id' are language code for 'English' and 'Indonesian'. Change it to the language code you want to use.
if ( qtrans_getLanguage() == 'language_code' )
You can check the full list of language codes that qTranslate plugin use on /wp-content/plugins/qtranslate/qtranslate.php. Search for "Full country names as locales for Windows systems" to jump on that section.
- Save the changes. Now you have different menu for each language.
The code above may can be used for different themes, just try to locate where your theme's wp_nav_menu is and replace it with the code above. But again, I have only tried it on Twenty Twelve theme and its child themes.
I hope it can be useful for you. Please share your comments below. Cheers! 🙂