I added a function to show a language button in nav menu, but the issue is that I have more than one menu and it duplicates the result. How can I specify what menu I want to show the language button in?
This is my code:
function new_nav_menu_items($items,$args) {
if (function_exists('icl_get_languages') && !empty($args->theme_location)) {
$languages = icl_get_languages();
$current_lang = ICL_LANGUAGE_CODE;
$nitem = "";
if(count($languages) >= 1){
foreach($languages as $l){
if( $l['language_code'] != $current_lang ) {
$nitem .= '<li class="menu-item"><a href="'.$l['url'].'"> '.$l['native_name'].'</a></li>';
}
}
}
}
return $items . $nitem;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items', 10,2 );