Make WordPress Core

Opened 14 years ago

Closed 6 years ago

#13910 closed feature request (fixed)

Get Menu name with wp_nav_menu()

Reported by: jowo's profile jowo Owned by: chriscct7's profile chriscct7
Milestone: 4.9 Priority: normal
Severity: normal Version: 3.0
Component: Menus Keywords: has-patch has-unit-tests commit
Focuses: Cc:

Description

There is no way to get the actual "Menu name" in wp_nav_menu()

For example if you want to create a left sidebar menu you want a header to go with it. In previous versions you could do use wp_list_pages() with "title_li".

With wp_nav_menu() you have to hard code <h3>Static menu name</h3> into the template before calling the function.

If you could get the "Menu name" as defined in backend interface from the wp_nav_menu() it would create the menu title automatically.

Attachments (5)

13910.diff (1.2 KB) - added by wojtek.szkutnik 14 years ago.
13910-2.diff (1.6 KB) - added by christophherr 8 years ago.
Turns markoheijnen's comment into a patch. Adds filter for the title of a navigation menu.
13910.tests.patch (892 bytes) - added by SpencerFinnell 7 years ago.
Add tests for wp_nav_menu_title()
13910.patch (1.1 KB) - added by sagarprajapati 7 years ago.
13910.2.patch (1.1 KB) - added by welcher 7 years ago.
Combined patch

Download all attachments as: .zip

Change History (31)

#1 @ocean90
14 years ago

  • Milestone changed from 3.0 to Future Release

#2 @pavelevap
14 years ago

  • Cc pavelevap@… added

#3 @wojtek.szkutnik
14 years ago

  • Cc wojtek.szkutnik@… added
  • Keywords has-patch needs-testing added; wp_nav_menu menu name removed

#4 @wojtek.szkutnik
14 years ago

  • Keywords gsoc added

#5 @dangayle
13 years ago

+1 I've needed this a few times, having to resort to a similar solution to http://www.wptavern.com/forum/themes-templates/1563-list-available-wp_nav_menus.html

#6 @markoheijnen
12 years ago

  • Cc marko@… added
  • Keywords dev-feedback added; gsoc removed

The patch looks wrong. title shouldn't be an argument and it should have been $menu->name.

Also a function like this should be in core

<?
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 );
}
?>

#7 @DrewAPicture
12 years ago

  • Cc xoodrew@… added

#8 @chriscct7
9 years ago

There was about 10 comments from the same user that were moderated as spam (which I confirmed they were). Reviewed and deleted them.

This ticket was mentioned in Slack in #core by chriscct7. View the logs.


8 years ago

@christophherr
8 years ago

Turns markoheijnen's comment into a patch. Adds filter for the title of a navigation menu.

#10 @christophherr
8 years ago

  • Keywords needs-unit-tests added

Following what chriscct7 said in Slack, 13910-2.diff turns markoheijnen's comment into a patch.

@SpencerFinnell
7 years ago

Add tests for wp_nav_menu_title()

#11 @SpencerFinnell
7 years ago

  • Keywords has-unit-tests 4.8-early added; needs-testing needs-unit-tests removed

#12 @chriscct7
7 years ago

  • Keywords 4.8-early removed
  • Milestone changed from Future Release to 4.8

#13 @chriscct7
7 years ago

  • Owner set to chriscct7
  • Status changed from new to reviewing

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


7 years ago

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


7 years ago

#16 @jbpaul17
7 years ago

  • Milestone changed from 4.8 to 4.8.1

Punting to 4.8.1 per today's bug scrub.

#17 @sagarprajapati
7 years ago

  • Keywords dev-feedback removed

Hi All,

I have checked the 13910-2.diff patch and it's working as expected. I have updated @since as 4.8.1 in refreshed patch because its milestone is changed to 4.8.1

Thanks

This ticket was mentioned in Slack in #core by sagarprajapati. View the logs.


7 years ago

#19 @welcher
7 years ago

  • Keywords commit added

Unit tests passed for me. Adding combined patch for the feature and the tests. I think this is good to go.

@welcher
7 years ago

Combined patch

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


7 years ago

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


7 years ago

#22 @jbpaul17
7 years ago

  • Milestone changed from 4.8.1 to 4.9

Punting per today's bug scrub and since 4.8.1 is focused on regressions.

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


6 years ago

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


6 years ago

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


6 years ago

#26 @SergeyBiryukov
6 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 41766:

Menus: Introduce wp_get_nav_menu_name() to retrieve the name of a navigation menu as set in the admin.

Props markoheijnen, christophherr, SpencerFinnell, wojtek.szkutnik, sagarprajapati, welcher, SergeyBiryukov.
Fixes #13910.

Note: See TracTickets for help on using tickets.