-
AuthorPosts
-
April 11, 2014 at 4:25 pm #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 youApril 14, 2014 at 8:44 am #250934Hi 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 10 years, 8 months ago by Dude.
May 3, 2017 at 5:51 pm #787263Hi,
this still works fine, thank you!
Best regards
Mike -
AuthorPosts
- The topic ‘[Enfold + WPML] Menu language switcher’ is closed to new replies.