Posted By

Huskie on 09/09/11


Tagged

menu location format wordpress name slug parameter theme


Versions (?)

Get WordPress theme menu name in slug format from location parameter


 / Published in: PHP
 

URL: http://darrenhuskie.com/

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

  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. }

Report this snippet  

You need to login to post a comment.