Diagnosis

wp_nav_menu is called twice with the same theme_location parameter (UberMenu 2)

23

Some themes call wp_nav_menu twice with the same theme_location parameter – doing so may have strange results.

Background

UberMenu is applied to a particular wp_nav_menu call based on the theme_location parameter.

UberMenu can only be applied once per page, so the first will become an UberMenu, and the rest will not be affected.

The Problem

Some themes call wp_nav_menu twice with the same theme_location parameter – sometimes to produce a responsive menu, sometimes to test for the menu’s existence.

Responsive menu theme conflict

In the common responsive menu case, both menus may be printed in order to create a responsive menu. The order in which the menus are printed will affect the outcome. See also this FAQ for details. Here is the common pattern:

<div id="nav">
    <?php 
    //This order may vary

    // this is the menu you'll see at widths greater than 960px
    wp_nav_menu( array( 'theme_location' => 'main_menu',  'container_class' => 'main-menu-standard' ) );
 
    // this is the menu that will be displayed on mobile devices
    wp_nav_menu( array( 'theme_location' => 'main_menu',  'container_class' => 'main-menu-responsive', 'walker' => 'responsive_walker' ) ); 
    ?>
</div>

Scenario A: Theme prints responsive menu first

In Scenario A, the first wp_nav_menu call is intended to be the theme’s responsive menu. However, since it uses the same theme location that you’ve activated, UberMenu will be applied to this wp_nav_menu call. Remember, the theme intends to hide the responsive menu at larger widths. The second call will be unaffected by UberMenu, and continue to show the theme menu. This leads to two variations –

Scenario A variation 1: UberMenu hidden

If the theme’s CSS continues to apply, UberMenu will be hidden. In this variation, it seems that UberMenu has done nothing at all; in fact, it has replaced the responsive menu, and if you resize your site it will likely display.

Scenario A variation 2: Both menus appear

If the theme’s CSS no longer applies to the “responsive” menu, you will see both menus now appearing.

In UberMenu 2.4+ you can set your menu to use the second instance of the theme location instead through the Control Panel. See What to do if UberMenu replaces your responsive menu but not your main menu

Scenario B: Theme prints responsive menu second

In this scenario, UberMenu will be applied to the menu that is normally shown, but will not be applied to the responsive menu. This can result in both menus being shown or UberMenu being hidden at responsive sizes.

The solution in all scenarios is the same: remove the extra wp_nav_menu call. UberMenu doesn’t need two wp_nav_menu calls to be responsive

Existence testing

UberMenu 2 will only be applied the FIRST time the function is called. In the event that the first call is not printed, UberMenu will be applied to that menu only, so it will never show up (the first call isn’t printed, and the second is ignored because it has already been applied).

Identifying the issue

You’ll need to find the wp_nav_menu function call and check the parameters that are being passed to it. This function is called in the header.php under normal circumstances, but you may need to do a global search on your theme files to locate it. Look for the wp_nav_menu call being made twice with the same theme_location parameter.

Responsive Menus

The first call may print the menu, but it may be hidden with CSS by your theme, as it intends for this to be a mobile menu. The second menu is displayed as the theme normally would, since UberMenu will only apply to the first call.

Existence testing

If the first call with that theme_location has the echo parameter set to false, that’s the issue.

The Solution

Responsive Menus

If your theme uses responsive menus, the best solution is generally to replace the entire menu block (both wp_nav_menu calls) with UberMenu Direct. Alternatively, simply remove the mobile menu wp_nav_menu call, as it is superfluous (note that you still may have residual styling depending on how the menu was coded in the theme which could hide UberMenu at the wrong time, which is why replacing the entire menu block is recommended). See this FAQ for further details and options.

Existence Testing

If a menu is being processed but not printed, it may be a check for the menu’s existence. It is much better to use the has_nav_menu function instead of wp_nav_menu in this instance. This has been identified as an issue with Geothemes, for instance.