patrickgilmour
6/22/2014 - 8:52 PM

[WordPress] Retrieve and show the name of a WordPress menu using #wp_get_nav_menu_object

[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;

}