Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #250273

    Hi!
    I’m tring to put the language switcher ( ITA | ENG ) at the end (float:right) of the main menu of a website but with no success.
    How can i do it?
    I need to color differently the language actually in use and the other.
    Thank you

    #250934

    Hi morgantar!

    Since 2.6 Enfold will add flags to the main menu. If you want to display the language shortcode instead of the flag images insert this code into your 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 )
            {
                if ((is_object($args) && $args->theme_location == 'avia'))
                {
                    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='language_".$lang['language_code']." $currentlang'><a href='".$lang['url']."'>";
                            $items .= $lang['language_code'];
                            $items .= "</a></li>";
                        }
                    }
                }
                return $items;
            }
        }
    

    (alternatively insert the code at the very top of enfold/functions.php after the <?php tag). You can also replace $lang[‘language_code’] with

    $lang[‘translated_name’]

    or

    $lang[‘native_name’]

    if you want to display the entire language name (and not just the shortcode).

    Best regards,
    Peter

    • This reply was modified 9 years, 11 months ago by Dude.
    #787263

    Hi,

    this still works fine, thank you!

    Best regards
    Mike

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘[Enfold + WPML] Menu language switcher’ is closed to new replies.