public
Created

wpml forum topic: display-the-language-switcher-in-the-wp-menu; show all langauges but the current one

  • Download Gist
wpml-language-switch.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<?php
// add the following lines to the functions.php file of your theme
function wpml_language_switch() {
$lang = icl_get_languages('skip_missing=N');
$ret = '';
if(count($lang) > 0) {
foreach($lang as $value) {
$ret .= ($value['active'] == 0) ? '<li class="language dropdown menu-item"><a href="' . $value['url'] . '">' .
$value['native_name'] . '</a></li>' : '';
}
}
return $ret;
}
// end add
 
?>
 
// add the following lines to the header.php file of your theme, on the place where you are calling the navigation menu
// maybe for your theme you have to change the container_id and/or the items_wrap and/or the class
<?php // Check to see whether WPML is active, if it is we include the Language Switcher in the navigation menu - source: http://webdesign.onyou.ch/2010/07/28/check-if-a-wordpress-plugin-is-active/ ?>
<?php if (in_array( 'sitepress-multilingual-cms/sitepress.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) {
wp_nav_menu( array('container_id' => 'nav', 'items_wrap' => '<ul id="%1$s" class="menu menu-primary">%3$s' .wpml_language_switch().'</ul>', 'theme_location' => 'primary' ) );
} else {
wp_nav_menu( array('container_id' => 'nav', 'items_wrap' => '<ul id="%1$s" class="menu menu-primary">%3$s</ul>', 'theme_location' => 'primary' ) );
} ?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.