Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #294265

    Hi,

    I like to show NL | EN instead of the native flags from WPML.
    I have followed some instructions for the WPML config.php, but they seem old from 2013.
    What’s the process to get country codes instead of flags in the main menu or top menu?

    For now, I did

    foreach($languages as $lang)
    				{
    					$currentlang = (ICL_LANGUAGE_CODE == $lang['language_code']) ? 'avia_current_lang' : '';
    
    					if(!avia_is_overview() && (is_home() || is_front_page())) $lang['url'] = $sitepress->language_url($lang['language_code']);
    					         
    					$output .= "<li class='language_".$lang['language_code']." $currentlang'><a>";
    					// $output .= "	<span class='language_flag'><img /></span>";
    					// $output .= "	<span class='language_native'>".$lang['native_name']."</span>";
    					// $output .= "	<span class='language_translated'>".$lang['translated_name']."</span>";
    					$output .= "	<span class='language_code'>".$lang['language_code']."</span>";
    					$output .= "</a></li>";
    				}

    But it doesn’t work. Nothing changes. I work local, can’t provide a link yet.

    Thanks

    S

    • This topic was modified 10 years, 3 months ago by Yigit.
    #294525

    Hey Spiv!

    Please insert this code into the quick css field and revert the php code changes you posted above.

    
    .avia_wpml_language_switch li .language_flag img { display: none; }
    .avia_wpml_language_switch li .language_code { display: block!important; }
    

    Regards,
    Peter

    #301122

    My icons are still showing. like to show IT | EN

    I have the icons dispaying in the header menu:

    <li class="language_en avia_current_lang"><a href="#"><span class="language_flag"><img src="http://www.mysite.com/wp-content/plugins/sitepress-multilingual-cms/res/flags/en.png" /></span></a></li>

    • This reply was modified 10 years, 3 months ago by royaltask.
    #301223

    Hi!

    Try to add this code to the theme (or 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))
    		        {
    		            $num_el = $total_el = count($languages);
    
    		            foreach($languages as $lang)
    		            {
    		               $num_el--;
    		                $currentlang = (ICL_LANGUAGE_CODE == $lang['language_code']) ? 'avia_current_lang' : '';
    		
    		                if(is_home() || is_front_page()) $lang['url'] = $sitepress->language_url($lang['language_code']);
    
    		                $style = ($num_el != $total_el) ? ' padding-left:5px;' : '';
    		
    		                $items .= "<li class='language_".$lang['language_code']." $currentlang'><a style='padding-right:0;{$style}' href='".$lang['url']."'>";
    		                $items .= "	<span class='language_flag'>".strtoupper($lang['language_code'])."</span>";
    		                if($num_el > 0) $items .= " | ";
    		                $items .= "</a></li>";
    
    		            }
    		        }
    		    }
    		    return $items;
    		}
    	}
    
    

    Best regards,
    Peter

    #301556

    Not working for my Menu: mine looks like this:
    t

    i would like to show it like this:
    t

    #301758

    Hey!

    I noticed if you don’t use a child theme you must place the code at the very top of the enfold/functions.php file. Open up the file and replace:

    
    <?php
    
    global $avia_config;
    

    with

    
    <?php
    
    global $avia_config;
    
    	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))
    		        {
    		            $num_el = $total_el = count($languages);
    
    		            foreach($languages as $lang)
    		            {
    		               $num_el--;
    		                $currentlang = (ICL_LANGUAGE_CODE == $lang['language_code']) ? 'avia_current_lang' : '';
    		
    		                if(is_home() || is_front_page()) $lang['url'] = $sitepress->language_url($lang['language_code']);
    
    		                $style = ($num_el != $total_el) ? ' padding-left:5px;' : '';
    		
    		                $items .= "<li class='language_".$lang['language_code']." $currentlang'><a style='padding-right:0;{$style}' href='".$lang['url']."'>";
    		                $items .= "	<span class='language_flag'>".strtoupper($lang['language_code'])."</span>";
    		                if($num_el > 0) $items .= " | ";
    		                $items .= "</a></li>";
    
    		            }
    		        }
    		    }
    		    return $items;
    		}
    	}
    
    

    Then the code should work.

    Regards,
    Peter

    #302513

    Now working Peter, thank you so much!

    Advanced: to make the active language underlined, I tried this:
    .avia_wpml_language_switch li .language_flag img { display: none; }
    .avia_wpml_language_switch li .language_code { display: block!important; }
    .avia_wpml_language_switch .avia_current_lang .language_flag { text-decoration: underline!important; }

    No Luck so far.

    • This reply was modified 10 years, 3 months ago by royaltask.
Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘WMPL country code instead of flags’ is closed to new replies.