Skip to content

Instantly share code, notes, and snippets.

@esoileme
Created March 23, 2018 11:10
Show Gist options
  • Save esoileme/a55a34fa6b86c3b26ee2807bd89a7b4b to your computer and use it in GitHub Desktop.
Save esoileme/a55a34fa6b86c3b26ee2807bd89a7b4b to your computer and use it in GitHub Desktop.
Display the country code on specific menu location with wpml
// Filter wp_nav_menu() to add additional links and other output
function new_nav_menu_items($items,$args) {
if ($args->theme_location == 'primary-menu') {
if (function_exists('icl_get_languages')) {
$languages = icl_get_languages('skip_missing=0');
if(1 < count($languages)){
foreach($languages as $l){
if(!$l['active']){
$items = $items.'<li class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-00000"><a href="'.$l['url'].'">'.$l['language_code'].'</a></li>';
}
}
}
}
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items',10,2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment