I am trying to add to my menu bar some language elements. I’m using the qTranslate plugin and I would like to add the language switch to the menu bar.
My them is calling in the header.php
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu'));?>
And then I added to my functions.php the following code, which remains without effect :
function qtrans_generateLanguageListCode($id='') {
global $q_config;
if(is_404()) $url = get_option('home'); else $url = '';
if($id=='') $id = 'qtranslate';
$id .= '-chooser';
foreach(qtrans_getSortedLanguages() as $language) {
$classes = array('lang-'.$language);
if($language == $q_config['language'])
$classes[] = 'active';
echo '<li class="'. implode(' ', $classes) .'"><a href="'.qtrans_convertURL($url, $language).'"';
// set hreflang
echo ' hreflang="'.$language.'" title="'.$q_config['language_name'][$language].'"';
echo ' class="qtrans_flag qtrans_flag_'.$language.'"';
echo '><span';
echo ' style="display:none"';
echo '>'.$q_config['language_name'][$language].'</span></a></li>';
}
}
function new_nav_menu_items($items) {
$translinks = qtrans_generateLanguageListCode();
$items = $items . $translinks;
return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' );
Could anyone help me to understand what I am missing ? I have to add that I am using a child theme of Twenty Twelve, but this should be without effect.
Thanks !
You have to
return
the data in the qtrans function: