admin管理员组

文章数量:1430513

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:

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'

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:

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'

Share Improve this question edited May 13, 2019 at 7:11 BonisTech asked May 13, 2019 at 6:59 BonisTechBonisTech 2721 silver badge9 bronze badges 2
  • Can you please confirm if you have registered secondary menu? – Nilambar Sharma 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
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: phpwpnavmenu not working correctly in my underscores theme