Tagged: language selector, wpml
-
AuthorPosts
-
May 24, 2015 at 10:26 pm #449299
Hi!
How can i have the WPML language switcher to appear on the menu regardless of which menu the page uses.
I have a couple of different menus showing, depending on which page your’ on.
May 26, 2015 at 5:44 am #449799Hi Paul,
What method are you using to include the flags? can you please create us a WordPress administrator account? post it here as a private reply.
Regards,
JosueMay 26, 2015 at 9:10 am #449896This reply has been marked as private.May 28, 2015 at 7:11 am #450950I got this from WPML
Hi Paul,
Thanks for contacting support forum.
WPML’s in-built language switcher has very limited options. By using language switcher options present at WPML > Languages > Language Switcher Options > Language switcher in the WP Menu, you can add language switcher in any one menu. To add language switchers in multiple menus, it is required to add the language switcher programatically.Following is a code which will add language switcher to different menus.
function wpml_add_menu_item( $items, $args ) { $theme_locations = array( 'primary', 'secondary', 'footer-menu', 'sidebar-menu' ); if( !empty( $args->theme_location ) && in_array( $args->theme_location, $theme_locations ) ) { ob_start(); ?> <li class="menu-item ls-menu"><?php echo do_action('icl_language_selector'); ?></li> <?php $items .= ob_get_contents(); ob_end_clean(); } return $items; } add_filter('wp_nav_menu_items', 'wpml_add_menu_item', 10, 2);
It is adding language switcher to the menu based on theme location of menu declared in,
$theme_locations = array( 'primary', 'secondary', 'footer-menu', 'sidebar-menu' );
You can add theme location of menus to which you want to add language switcher. I would suggest you to ask for help to your theme author if you are not clear about the same.
For more information, on wordpress navigation menus, please refer: https://codex.wordpress.org/Navigation_Menus
Hope this helps.
Regards
Ankit G.Should i paste the code in the Functions.php ?
Also how can i determine how to alter the code so it includes all/or specific menus ?
Thanx!
May 28, 2015 at 11:57 pm #451477Hey!
Try adding this at the very end of your theme / child theme functions.php file:
if(!function_exists('avia_append_lang_flags')) { //first append search item to main menu add_filter( 'wp_nav_menu_items', 'avia_append_lang_flags', 20, 2 ); add_filter( 'avf_fallback_menu_items', 'avia_append_lang_flags', 20, 2 ); function avia_append_lang_flags( $items, $args ) { global $avia_config, $sitepress; if(empty($avia_config['wpml_language_menu_position'])) $avia_config['wpml_language_menu_position'] = apply_filters('avf_wpml_language_switcher_position', 'main_menu'); if($avia_config['wpml_language_menu_position'] != 'main_menu') return $items; $languages = icl_get_languages('skip_missing=0&orderby=custom'); if(is_array($languages)) { foreach($languages as $lang) { $currentlang = (ICL_LANGUAGE_CODE == $lang['language_code']) ? 'avia_current_lang' : ''; if(is_home() || is_front_page()) $lang['url'] = $sitepress->language_url($lang['language_code']); $items .= "<li class='av-language-switch-item language_".$lang['language_code']." $currentlang'><a href='".$lang['url']."'>"; $items .= " <span class='language_flag'><img title='".$lang['native_name']."' src='".$lang['country_flag_url']."' /></span>"; $items .= "</a></li>"; } } return $items; } }
Cheers!
JosueMay 29, 2015 at 2:33 am #451501Hi!
I added that to the themes functions.php
But as i can see there is no difference, once i get to a page that doesn’t have the main menu as default menu, the flags are gone ?
Do i need something with the settings in WPML or in the Enfold theme settings ?
Thanx!
May 30, 2015 at 7:26 am #451926Hey!
I checked both pages and the flags display on both of them. Please remove browser cache then reload the page.
Regards,
IsmaelMay 30, 2015 at 9:05 am #451951Hi!
I cleared the cache and tried on different computers still only flags present on pages which has the main menu as default menu.
For instance if i pick one the locations flags doesn’t show.
can you see the flags on this page ?
http://www.hattorisushidevil.se/drottninggatan/meny/smaratter/
June 1, 2015 at 8:10 am #452362June 1, 2015 at 2:43 pm #452552Hi!
Yes i use the plugin zenmenu.
Is there another solution to have pages display different menus ?
I need the language switcher on the menu so that you can change language on the mobile site as well.
June 5, 2015 at 9:48 am #455017Hi!
If you are using a plugin for it, I would suggest to contact the Plugin author, you will help you out with that.
We do not provide support for 3rd party plugin.Best regards,
BasilisJune 10, 2015 at 10:19 am #457078Hi Thanx! I removed the plugin and using just one menu. thanx
-
AuthorPosts
- The topic ‘WPML language switcher on the menu with several different menus ?’ is closed to new replies.