0

I'm using a theme based on underscores, and I have registered my menus in the following way.

function register_my_menu() {
    register_nav_menus( array(
        'primary' => esc_html__( 'Primary' ),
        'social_media' => esc_html__( 'Social Media' ),
    ) );
};
add_action( 'init', 'register_my_menu' );

When calling the menus like so:

wp_nav_menu(
    ['theme_location' => 'primary']
);

wp_nav_menu(
    ['theme_location' => 'social_media']
);

only the primary menu shows up.

I checked if themenu exists and is registered with has_nav_menu() and it returns true.

Here is my backend. The menu is registered and assigned to a location:

enter image description here

No, it's not on display none. I checked the markup, and it's empty.

I disabled JS and it's still the same. I tried adding a new menu:

…
    'secondary' => esc_html__( 'Secondary' ),
…

and went through all the procedure, and when calling

wp_nav_menu(
    ['theme_location' => 'secondary']
);

nothing happens. Markup is still empty. Somehow it's only working with the name 'primary'

2
  • Can you please confirm if you have registered secondary menu? Commented May 13, 2019 at 8:19
  • "The menu is registered and assigned to a location" - you do have menu items in the "Social Media" menu? Do you have custom functions/code which may be filtering items in that menu (location)?
    – Sally CJ
    Commented May 13, 2019 at 13:50

1 Answer 1

1

If found out that this is removing my menu:

function add_menu_icon ( $items, $args ) {
    if ( $args->theme_location == 'primary' ) {
        $elements = '<li class="custom-logo">'
                    .   get_custom_logo()   .
                    '</li>';
                    $elements .= $items;
        $items = $elements;
        return $items;
    }
}
add_filter( 'wp_nav_menu_items', 'add_menu_icon', 10, 2 );

I still haven't figured out why.

1
  • 2
    You need to always return the $items. So move the return $items; to outside the if block: if ( $args->theme_location == 'primary' ) { ... } return $items; // <- here
    – Sally CJ
    Commented May 14, 2019 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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