Created
April 11, 2016 23:15
-
-
Save hauge75/b9d6fbdb705efe39c93482cc04a1af6a to your computer and use it in GitHub Desktop.
WPML language selector in menu - hide current language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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