Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save erezLieberman/118db002a4bed4528a32 to your computer and use it in GitHub Desktop.
Save erezLieberman/118db002a4bed4528a32 to your computer and use it in GitHub Desktop.
Showed the opposite language ןin WPML language switcher
function my_custom_switcher( $items, $args ){
if( $args->theme_location == 'primary' ) {
$languages = icl_get_languages('skip_missing=0&orderby=code');
if(!empty($languages)){
ob_start(); ?>
<?php
foreach($languages as $l){
if( !$l['active'] ){ ?>
<li class="other_lang">
<a href="<?php echo $l['url']; ?>">
<?php echo $l['native_name'] ?>
</a>
<?php
}
} ?>
<?php
$items .= ob_get_contents();
ob_end_clean();
}
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'my_custom_switcher', 10, 2 );
@erezLieberman
Copy link
Author

Add this code to functions.php in your theme
based on this Discussion:
https://wpml.org/forums/topic/change-the-language-order-in-menu-language-switcher/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment