Skip to content

Instantly share code, notes, and snippets.

@abdallah
Last active September 9, 2015 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdallah/7337512daf14c82d7540 to your computer and use it in GitHub Desktop.
Save abdallah/7337512daf14c82d7540 to your computer and use it in GitHub Desktop.
WPML custom switcher to show "other" languages
<?php
function other_languages_switcher(){
$languages = icl_get_languages('skip_missing=1');
foreach($languages as $l){
if(!$l['active']) {
$langs[] = '<a href="'.$l['url'].'">'.$l['language_code'].'</a>';
}
}
echo join(', ', $langs);
}
/* another version
adds the switcher in the menu
with wpml_ instead of icl_ functions
*/
add_filter('wp_nav_menu_items', 'new_nav_menu_items', 10, 2);
function new_nav_menu_items($items, $args) {
// change $args->theme_location == 'primary-menu' to specify the menu location that matches your theme.
if (has_filter('wpml_active_languages') && $args->theme_location == 'primary') {
$languages = apply_filters( 'wpml_active_languages', NULL, array( 'skip_missing' => 0 ) );
foreach($languages as $l){
if(!$l['active']) {
$items = $items . '<li class="menu-item menu-item-language"><a href="'.$l['url'].'"><img src="'.$l['country_flag_url'].'" alt="'.$l['language_code'].'" ></a></li>';
}
}
}
return $items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment