Advertisement
shekhar77

WPML Language switcher, Languages as a default dropown value

Aug 19th, 2016
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. /*
  2. Added by WPML Support
  3. */
  4.  
  5. add_filter('wp_nav_menu_items', 'new_nav_menu_items', 10, 2);
  6. function new_nav_menu_items($items, $args) {
  7. // uncomment this to find your theme's menu location
  8. //echo "args:<pre>"; print_r($args); echo "</pre>";
  9.  
  10. // get languages
  11. $languages = apply_filters( 'wpml_active_languages', NULL, 'skip_missing=0' );
  12.  
  13. // add $args->theme_location == 'primary-menu' in the conditional if we want to specify the menu location.
  14.  
  15. if ( $languages && $args->theme_location == 'primary') {
  16.  
  17. if(!empty($languages)){
  18.  
  19. $item_new = '<li class="menu-item"><a>'. __('Languages', 'custom_switcher') .'</a><ul class="sub-menu">';
  20.  
  21. foreach($languages as $l){
  22. // flag with native name
  23. $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>';
  24. //only flag
  25. //$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>';
  26.  
  27. }
  28. $item_new .= '</ul></li>';
  29.  
  30. $items = $items . $item_new;
  31. }
  32. }
  33.  
  34. return $items;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement