WordPress 4.0 Menu Behavior Change

I recently upgraded a site to the new WordPress 4.0.  As usual, there were no noticeable hiccups… until I looked at my main navigation more closely a couple of days later.  I have a couple menus defined but one called “Primary Navigation” – a pretty typical set up.  I’ve written my own theme, as I have for many, many sites and have used the same menu code for as long as I can remember:

// after_setup_theme callback
register_nav_menus( array( 'primary' => __( 'Primary Navigation',
           'somethingidontrememberwhyitisshereandcantfinditinthedocs' ), ) );

// in template menu 
wp_nav_menu( array('menu' => 'Primary Navigation' ))

This was causing a different menu to show up in the location of the wp_nav_menu.

A quick web search showed I wasn’t the only one running into this as well as no obvious indicators of changes in the behavior of wp_nav_menu. There was a hint, and I followed it, that changing to the actual name of the menu would fix this – and it did. My code now reads:

wp_nav_menu( array('menu' => 'Main Navigation' ))

“Main Navigation” is the actual name of the menu I defined inside of my site.

This doesn’t seem quite right having to know the exact menu name instead of allowing a menu to be abstractly identified and then mapped.

I also tried:

  • switching to using register_nav_menu
  • switching to using the menu identifier/slug “primary”
    • WordPress codex for wp_nav_menu says the menu parameter “accepts (matching in order) id, slug, name”
    • Reminder that the second parameter for register_nav_menu is a “description” not a “name”

Only using the actual menu name worked. 

Advertisements

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: