Skip to content

Instantly share code, notes, and snippets.

@hauge75
Created April 11, 2016 23:15
Show Gist options
  • Save hauge75/b9d6fbdb705efe39c93482cc04a1af6a to your computer and use it in GitHub Desktop.
Save hauge75/b9d6fbdb705efe39c93482cc04a1af6a to your computer and use it in GitHub Desktop.
WPML language selector in menu - hide current language
<?php
// Filter wp_nav_menu() to add additional links and other output
add_filter('wp_nav_menu_items', 'new_nav_menu_items', 10, 2);
function new_nav_menu_items($items, $args) {
// add $args->theme_location == '[location]' in the conditional if we want to specify the menu location.
if (function_exists('icl_get_languages') && $args->theme_location == 'primary-menu') {
$languages = icl_get_languages('skip_missing=0');
if(!empty($languages)){
foreach($languages as $l){
if(!$l['active']){
// flag with native name
//$items = $items . '<li class="menu-item"><a href="' . $l['url'] . '"><img src="' . $l['country_flag_url'] . '" height="12" alt="' . $l['language_code'] . '" width="18" /> ' . $l['native_name'] . '</a></li>';
//only flag
$items = $items . '<li class="menu-item menu-item-language"><a href="' . $l['url'] . '"><img src="' . $l['country_flag_url'] . '" height="12" alt="' . $l['language_code'] . '" width="18" /></a></li>';
}
}
}
}
return $items;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment