Last active
September 9, 2015 11:04
-
-
Save abdallah/7337512daf14c82d7540 to your computer and use it in GitHub Desktop.
WPML custom switcher to show "other" languages
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 | |
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