Skip to content

Instantly share code, notes, and snippets.

@BronsonQuick
Created May 16, 2012 01:35
Show Gist options
  • Save BronsonQuick/2706609 to your computer and use it in GitHub Desktop.
Save BronsonQuick/2706609 to your computer and use it in GitHub Desktop.
Output the menu name in WordPress
<?php
/* This function returns the menu name */
function wp_nav_menu_title( $theme_location ) {
$title = '';
if ( $theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $theme_location ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $theme_location ] );
if( $menu && $menu->name ) {
$title = $menu->name;
}
}
return apply_filters( 'wp_nav_menu_title', $title, $theme_location );
}
/* Then in your theme you'll want to echo it out. e.g. <h3><?php echo wp_nav_menu_title('document'); ?></h3>
* The menu location is set in your register_nav_menu in functions.php
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment