Get WordPress theme menu name in slug format from location parameter


/ Published in: PHP
Save to your folder(s)

Example call: $menuName = sleek_get_theme_menu_name('footer-menu')


Copy this code and paste it in your HTML
  1. /*-----------------------------------------------------------
  2. Get a theme menu name in slug format based on a
  3. location parameter.
  4. -----------------------------------------------------------*/
  5. function sleek_get_theme_menu_name($theme_location)
  6. {
  7. if(!$theme_location) return false;
  8.  
  9. $theme_locations = get_nav_menu_locations();
  10. if(!isset($theme_locations[$theme_location])) return false;
  11.  
  12. $menu_obj = get_term($theme_locations[$theme_location],'nav_menu');
  13. if(!$menu_obj) $menu_obj = false;
  14. if(!isset($menu_obj->name)) return false;
  15.  
  16. // Make a slug out of the menu name now we know it exists
  17. $menu_name = strtolower($menu_obj->name);
  18. $menu_name = str_replace(" ","-", $menu_name);
  19.  
  20. return $menu_name;
  21. }

URL: http://darrenhuskie.com/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.