Skip to content

Instantly share code, notes, and snippets.

@corilam
Last active November 20, 2016 08:30
Show Gist options
  • Save corilam/28ebfe2d4c32799e264f519962d7face to your computer and use it in GitHub Desktop.
Save corilam/28ebfe2d4c32799e264f519962d7face to your computer and use it in GitHub Desktop.
WPML Hide Languages in Custom Switcher with CSS
//Language Switcher
add_filter('wp_nav_menu_items', 'new_nav_menu_items', 10, 2);
function new_nav_menu_items($items, $args) {
//Places the Language switcher in theme menu location 'languages'
if (function_exists('icl_get_languages') && $args->theme_location == 'languages') {
$languages = icl_get_languages('skip_missing=0');
//Remove current language and assign language code name class to li item
if(!empty($languages)){
foreach($languages as $l){
if(!$l['active']){
$items = $items . '<li class="menu-item menu-item-language menu-item-language-current menu-item-has-children narrow lang-'. $l['language_code'].'"><a href="' . $l['url'] . '">' . $l['native_name'] .'<span class="icl_lang_sel_bracket"></span></a></li>';
}
}
}
}
return $items;
}
function language_scripts() {
if(ICL_LANGUAGE_CODE == 'us-en' || ICL_LANGUAGE_CODE =="us-fr" || ICL_LANGUAGE_CODE =="us-es"){ //us languages
wp_enqueue_style( 'style-us', get_template_directory_uri() . "css/us-styles.css", array(), null );
}
if(ICL_LANGUAGE_CODE == 'in-hi' || ICL_LANGUAGE_CODE =="in-en"){ //india languages
wp_enqueue_style( 'style-in', get_template_directory_uri() . "css/in-styles.css", array(), null );
}
}
add_action( 'wp_enqueue_scripts', 'language_scripts' );
.menu>li.lang-id,.menu>li.lang-in-hi,.menu>li.lang-in-en {
display:none !important;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment