Set Different Menu for Each Language When Using qTranslate Plugin and Twenty Twelve Theme on WordPress

7
Updated on 13 June 2021

Wordpress logo
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:

  1. 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.
  2. Then create second menu, say its name is "Menu 2 id". This will be shown on site's Indonesian version.
  3. 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.
  4. 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.

  5. 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! 🙂

7
First published by  on Last Modified on 13 June 2021.

7 Comments

Add new comment

Add A Comment

Your email address will not be published. Required fields are marked *