Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #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.

    http://hattorisushidevil.se

    #449799

    Hi 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,
    Josue

    #449896
    This reply has been marked as private.
    #450950

    I 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!

    #451477

    Hey!

    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!
    Josue

    #451501

    Hi!

    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!

    #451926

    Hey!

    I checked both pages and the flags display on both of them. Please remove browser cache then reload the page.

    Regards,
    Ismael

    #451951

    Hi!

    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/

    #452362

    Hi!

    How did you set a different menu? Did you use a plugin?

    Best regards,
    Ismael

    #452552

    Hi!

    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.

    #455017

    Hi!

    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,
    Basilis

    #457078

    Hi Thanx! I removed the plugin and using just one menu. thanx

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘WPML language switcher on the menu with several different menus ?’ is closed to new replies.