Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Filter wp_nav_menu() to add additional links and other output
- // Show only other language in language switcher
- // Use the new filter: https://wpml.org/wpml-hook/wpml_active_languages-2/
- add_filter('wp_nav_menu_items', 'new_nav_menu_items', 10, 2);
- function new_nav_menu_items($items, $args) {
- // uncomment this to find your theme's menu location
- //echo "args: <pre>"; print_r($args); echo "</pre>";
- // get languages
- $languages = apply_filters( 'wpml_active_languages', NULL, 'skip_missing=0' );
- // add $args->theme_location == 'primary-menu' in the conditional if we want to specify the menu location.
- if ( $languages && $args->theme_location == 'primary') {
- if(!empty($languages)){
- foreach($languages as $l){
- if(!$l['active']){
- // flag with native name
- $items = $items . '<li class="menu-item"><a href="' . $l['url'] . '"><img src="' . $l['country_flag_url'] . '" height="12" alt="' . $l['language_code'] . '" width="18" /> ' . $l['native_name'] . '</a></li>';
- //only flag
- //$items = $items . '<li class="menu-item menu-item-language"><a href="' . $l['url'] . '"><img src="' . $l['country_flag_url'] . '" height="12" alt="' . $l['language_code'] . '" width="18" /></a></li>';
- }
- }
- }
- }
- return $items;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement