I Am Developing A Custom Theme. I have registered nav menus as you can see below

                'hub_header_menu' => __('Header Menu', 'HUB_WP'),
                'hub_footer_menu' => __('Footer Menu', 'HUB_WP'),

Code Of Printing Menus

<div class="header-desktop">
            <?php wp_nav_menu([
                'theme_location' => 'hub_header_menu',
            ]); ?>

I have Some Menu Items With Submenu But the problem is that the ".sub-menu" class is missing in submenus and they are printing as simple menu item.Like Code In Code Below, the "Sample" Page Is Sub item of "Home" but it is printed as simple menu items instead of submenu item.

HTML output Menu Items

I want to get .sub-menu class to style it. If I remove theme_location than it works properly but whenever i put theme location, it starts causing problem.

1 Answer 1


Based on looking at the output HTML i'd have guessed this was because wp_nav_menu was using the fallback cb to render a wp_page_menu, the clue was the output of page_item classes instead of menu-item classes.

From the docs for wp_nav_menu args:

fallback_cb callable|false
If the menu doesn't exist, a callback function will fire.
Default is 'wp_page_menu'. Set to false for no fallback.

Which may have been an indicator that your nav menu registration code was not being registered on the right action, usually we hook these onto init in the theme's functions file.

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.