Skip to main content

WordPress Theme Displays Wrong Menu

A quick note about WordPress menus as I’ve just resolved a problem myself. I’m in the middle of trying to create a responsive theme for this blog (using Bootstrap 3.2, if you are interested) and when I added the menu using wp_nav_menu to embed it in header.php, and register_nav_menus to declare it in functions.php I thought I had finished.

Unfortunately, it appeared to display any menu except the one I wanted – until I deleted all the others.

Some careful reading and a guess, in the end, helpled me solve the problem. I was using ‘menu_id’ in wp_nav_menu instead of 'theme_location'. Using 'theme_location' made it all work.

So to be clear:

  • register_nav_menus ( array( 'kbs3-top-menu' => __( 'Top Menu', 'kajabity_bs3' ) ) ); – placed in (a function in) functions.php registers a theme location 'kbs3-top-menu', which is displayed as 'Top Menu' in Manage Locations when editing Theme menus (using __(..,..) to internationalise 'Top Menu'), and
  • wp_nav_menu( array( 'theme_location' => 'kbs3-top-menu' ) ); – placed in header.php will display the menu which you have assigned to that theme location in the Admin Menu editor.

I’m guessing that when I used ‘menu_id’ I would have to create an actual menu with that Id – which, of course, I hadn’t so WordPress defaulted to one of the others, presumably in numeric id order.  It wouldn’t matter if you only have one menu defined!

Hope this helps.

Tags:
Posted in WordPress

One comment on “WordPress Theme Displays Wrong Menu”

  1. MonkeyDKS says:

    This helped me a TON (as a theme user, not a developer). I’ve been having the same problem and realized that it was using the first menu ALPHABETICALLY, so I simply added a 0 in front of my main menu and everything works fine!

Leave a Reply

Your email address will not be published. Required fields are marked *

*