Skip to content

Instantly share code, notes, and snippets.

@patrickgilmour
Created June 22, 2014 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickgilmour/7b127ccd9085bcdbe4d0 to your computer and use it in GitHub Desktop.
Save patrickgilmour/7b127ccd9085bcdbe4d0 to your computer and use it in GitHub Desktop.
[WordPress] Retrieve and show the name of a WordPress menu using #wp_get_nav_menu_object
/**
* Get the name of a WordPress menu using wp_get_nav_menu_object'
*
*/
add_filter( 'the_content' , 'pg_show_nav_menu_title' );
function pg_show_nav_menu_title ( $content ) {
// ID of the menu you want
$nav_menu_id = 13;
//Get it into an object
$nav_menu_object = wp_get_nav_menu_object( $nav_menu_id );
//Get the name
$nav_menu_title = $nav_menu_object->name;
//String to return as Content
$content = 'Nav menu title: ' . $nav_menu_title . '<br>' . $content;
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment