Skip to content

Instantly share code, notes, and snippets.

@senlin
Created April 10, 2012 00:35
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 senlin/2347620 to your computer and use it in GitHub Desktop.
Save senlin/2347620 to your computer and use it in GitHub Desktop.
wpml forum topic: display-the-language-switcher-in-the-wp-menu; show all langauges but the current one
<?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' ) );
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment