Skip to content

Instantly share code, notes, and snippets.

@leanda
Last active September 26, 2015 17:02
Show Gist options
  • Save leanda/fa470e1a413fa2f40822 to your computer and use it in GitHub Desktop.
Save leanda/fa470e1a413fa2f40822 to your computer and use it in GitHub Desktop.
Get WordPress menu title
<?php echo get_menu_name( 'primary' ) ?>
/**
* Function to get the menu title
*/
function get_menu_name( $theme_location ) {
if( ! $theme_location ) return false;
$theme_locations = get_nav_menu_locations();
if( ! isset( $theme_locations[$theme_location] ) ) return false;
$menu_obj = get_term( $theme_locations[$theme_location], 'nav_menu' );
if( ! $menu_obj ) $menu_obj = false;
if( ! isset( $menu_obj->name ) ) return false;
return $menu_obj->name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment