-
AuthorPosts
-
July 22, 2014 at 11:07 am #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, 4 months ago by Yigit.
July 22, 2014 at 6:49 pm #294525Hey 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,
PeterAugust 7, 2014 at 2:29 pm #301122My 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, 4 months ago by royaltask.
August 7, 2014 at 5:31 pm #301223Hi!
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,
PeterAugust 8, 2014 at 11:49 am #301556Not working for my Menu: mine looks like this:
i would like to show it like this:
August 8, 2014 at 6:01 pm #301758Hey!
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,
PeterAugust 11, 2014 at 12:22 pm #302513Now 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, 4 months ago by royaltask.
-
AuthorPosts
- The topic ‘WMPL country code instead of flags’ is closed to new replies.