Make WordPress Core

Opened 14 years ago

Closed 12 months ago

#20289 closed defect (bug) (wontfix)

wp_nav_menu container is not set when menu isn't defined

Reported by: dannydehaan's profile dannydehaan Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3
Component: Menus Keywords: dev-feedback needs-patch
Focuses: administration Cc:

Description

When you use wp_nav_menu in your theme, but the actual menu isn't set via the backend menu interface, the container provided in the args is ignored and falls back to 'div'.

Attached diff always uses container provided in args, if 'div' or 'nav' is provided. If no container arg is provided, falls back to using 'div'.

wp_nav_menu(
	array(
		'theme_location' => 'main_menu',
		'container'      => 'nav',
		'menu_class'     => 'main-menu-navigation',
	)
);

To test this: Use this function in your theme, without assigning a menu to this theme_location.

Attachments (1)

nav-menu-template.diff (1.4 KB) - added by dannydehaan 14 years ago.

Download all attachments as: .zip

Change History (6)

#1 @CoenJacobs
14 years ago

  • Cc coenjacobs@… added
  • Keywords dev-feedback added

#3 @chriscct7
12 years ago

  • Keywords needs-patch added; has-patch needs-testing removed

The patch for this was declined by Nacin in #13998

#4 @chriscct7
11 years ago

  • Focuses administration added

#5 @callumbw95
12 months ago

  • Resolution set to wontfix
  • Status changed from new to closed

Hi All,

I have just read through this ticket and caught myself up with the history. As discussed, the current behavior is by design. wp_nav_menu is intended to render defined navigation menus and their associated containers. When no menu is specified, it explicitly falls back to wp_page_menu, which is a distinct function designed for rendering a list of pages with its own container. Changing wp_nav_menu to output a container for wp_page_menu fallback would be a significant architectural alteration, potentially leading to other inconsistencies or unintended side effects, and goes against the distinct roles of these two functions. Themes requiring a consistent wrapper regardless of whether a menu is defined can implement this wrapping directly around the wp_nav_menu call in their templates.

Because of the reasons mentioned and the extreme age of this ticket I have marked this ticket as wontfix, but please feel free to reopen the ticket and continue this discussion.

Note: See TracTickets for help on using tickets.