I’m trying to add a WPML language link in a wp_nav_menu with the code below. Unfortunately this doesn’t work, the function other_language(); that outputs a language url is being displayed above the < ul > and not within his < li > . How can I solve this
function my_nav_wrap() {
$wrap = '<ul id="%1$s" class="%2$s">';
$wrap .= '%3$s';
$wrap .= '<li>';
$wrap .= other_language();
$wrap .= '</li>';
$wrap .= '</ul>';
return $wrap;
}
function other_language(){
$languages = icl_get_languages('skip_missing=0&orderby=code');
if(!empty($languages)){
foreach($languages as $l){
if(!$l['active']){
echo '<a href="'.$l['url'].'"class="lang-button">';
echo $l['native_name'];
echo '</a>';
}
}
}
}