WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 2 years ago

#16679 closed defect (bug) (invalid)

wp_nav_menu treats menu_class differently for fallback

Reported by: Nonchalant Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Menus Keywords:
Focuses: Cc:

Description

I've found references to this issue, but no actual solution or prior ticket. Issue:

When using wp_nav_menu, the output manner of menu_class is different depending if a fallback is being used or not.

Menu:

$wp_nav_header = array(
    'theme_location' => 'primaryheader',
    'menu'            => '',
    'container'       => false,
    'container_class' => '',
    'container_id'    => '',
    'menu_class'      => 'sf-menu',
    'menu_id'         => '',
    'fallback_cb'     => 'wp_page_menu',
    'before'          => '',
    'after'           => '',
    'link_before'     => '',
    'link_after'      => '',
    'depth'           => 0,);
wp_nav_menu( $wp_nav_header);

Output without Fallback (Correct output):

<ul id="menu-default" class="sf-menu"><li...

Output with Fallback (Incorrect output):

<div class="sf-menu"><ul><li...

So despite setting 'sf-menu' in menu_class, it creates a container (which I had explicitly disabled). It also does not populate the unordered list with the mentioned class.

Thank you,

Noel

Change History (6)

comment:1 follow-up: @filosofo4 years ago

  • Keywords close added; needs-testing removed
  • Milestone changed from Awaiting Review to Future Release

The <div> element is being generated by your fallback, in this case wp_page_menu. You can expect the markup to vary from non-fallback to the extent that the fallback differs, and wp_page_menu does not have an argument to remove the wrapping <div> element.

Some possible ways to address this:

  • Use a fallback of your own creation that more closely resembles typical menu markup.
  • Open a ticket to make wp_page_menu to print markup more like standard wp_nav_menu.

comment:2 in reply to: ↑ 1 @Nonchalant4 years ago

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

Replying to filosofo:

The <div> element is being generated by your fallback, in this case wp_page_menu. You can expect the markup to vary from non-fallback to the extent that the fallback differs, and wp_page_menu does not have an argument to remove the wrapping <div> element.

Some possible ways to address this:

  • Use a fallback of your own creation that more closely resembles typical menu markup.
  • Open a ticket to make wp_page_menu to print markup more like standard wp_nav_menu.

Thank you for the explanation! I tried looking through the Codex too and hence was stumped by this. What I'll do is make a codex contribution once I've created a fallback of my own creation.

comment:3 @filosofo4 years ago

  • Keywords close removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

Thanks for improving the Codex. I'm sure others will benefit from the explanation.

comment:4 @filosofo4 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

comment:5 @filosofo4 years ago

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.