Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Added by WPML Support
- */
- 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)){
- $item_new = '<li class="menu-item"><a>'. __('Languages', 'custom_switcher') .'</a><ul class="sub-menu">';
- foreach($languages as $l){
- // flag with native name
- $item_new .= '<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>';
- }
- $item_new .= '</ul></li>';
- $items = $items . $item_new;
- }
- }
- return $items;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement