wordpress qtranslate plugin get current selected language

If you are using qtranslate wordpress plugin on your website and want to display content based on selected language. Then qTranslate plugin have one function to return selected language. Using this function you can display content based on selected language inside your theme’s PHP files.


    if(qtrans_getLanguage()=='en') {
      // add your code here if the current selected language is 'en' (English)
    } elseif(qtrans_getLanguage()=='de') {
      // add your code here if the current selected language de 'en' (German)
    }
    else {}

qTranslate plugin display different wp_nav_menu() based on selected language

If you are planning to display wp_nav_menu() based on selected language then following snippet will help you. It will display different wp_nav_menu() by selected language. First you have to add different menus inside your wordpress admin.

First you have to register menus inside functions.php add following lines of code inside your theme’s fuctions.php file

<?php 
if ( function_exists( 'register_nav_menus' ) ) {
    register_nav_menus(
        array(
          'menu-header-en' => 'Main Menu EN',
          'menu-header-de' => 'Main Menu DE'
        )
    );
} ?>

Then add following lines of code where you want to display this menu.

<?php wp_nav_menu( array(  'theme_location' => 'menu-header-' . qtrans_getLanguage() , 'sort_column' => 'menu_order', 'container_class' => 'header-navigation' ) ); ?>

Leave a Reply

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