1

I'm working on a theme with custom menus, currently using WP 4.0.1.

I'm registering two menus in functions.php:

register_nav_menus(
    array(
      'primary'   => __( 'Main Menu', 'wsy' ),
      'secondary' => __( 'Secondary Menu', 'wsy' )
    )
);

Then, displaying them in my header.php file:

<nav role="navigation">
    <?php
        wp_nav_menu(
            array(
                'theme_location' => 'primary',
                'depth'          => '1'
            )
        );
    ?>
</nav>

The problem is, when I select a specific menu from either the Menus page or the customizer, they stop showing up in my page. It doesn't matter which menu or which location, they just don't show up. When I reset the locations (choose "- Select -" from the dropdown) a default menu is shown.

WP_DEBUG is active, no errors. Tried it with WP 4.1, still nothing. Tried adding new menus, no luck. Tried with a single menu location and registering with register_nav_menu(); instead -- nothing works.

I even tried on a fresh WP install, no luck. Also tried without the depth parameter, nothing.

I'd appreciate any help with this. Thanks!

  • See this post on how to create a custom menu. Hope that helps :-) – Pieter Goosen Mar 25 '15 at 6:04
  • @PieterGoosen My code is written like that, but it's still not working. Thank you anyway Pieter :) – WSY Mar 25 '15 at 8:16
  • Test this on a freash install without plugins on one of the bundled themes like twentyfifteen. I suspect something in your theme is causing this issue. It is definitely not your code or the code in my linked answer. – Pieter Goosen Mar 25 '15 at 8:19
  • 1
    Your problem is not the code you have posted. Are you using any custom filter on WP_Query or the main query, or any function hooked to pre_get_posts or any instance of query_posts. – Pieter Goosen Mar 25 '15 at 8:33
  • 1
    @PieterGoosen You're right Pieter. I had a filter set on wp_nav_menu_items that was pulling in some extra items. I forgot I had commented the function responsible for returning those items... Wow, thank you so much for your help. I would have struggled a lot without your idea. – WSY Mar 25 '15 at 8:51
0

You might need to use 'add_theme_support' for 'nav-menus' as well. See line 2 below:

if ( function_exists('wp_nav_menu') ) {
  add_theme_support( 'nav-menus' );
  register_nav_menus( array( 
      'primary' => __( 'Main Menu', 'wsy' ), 
      'secondary' => __( 'Secondary Menu', 'wsy' )
      ) 
  );
}

Then display your menu like so:

$nav_menu = 'primary';
if ( has_nav_menu( $nav_menu ) ) {
echo '<nav role="navigation">';
  wp_nav_menu(
    array(
        'theme_location' => $nav_menu,
        'depth' => 1
    )
  );
echo '</nav>';
}
  • Still nothing :( The condition is met, the nav tags are echoed, but wp_nav_menu() still doesn't output anything :( – WSY Mar 25 '15 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.