wp_nav_menu doesn't seem to work on custom post type pages

I'm working on something someone else set up, and on the index page, the nav appears, but on custom post type pages, it does not.

The nav menu:

 wp_nav_menu([
                'menu'              = 'Primary Menu',
                'theme_location'    = 'primary',
                'depth'             = 3,
                'container'         = 'div',
                'container_class'   = 'a',
                'container_id'      = 'b',
                'menu_class'        = 'nav navbar-nav',
                'fallback_cb'       = 'wp_bootstrap_navwalker::fallback',
                'walker'            = new wp_bootstrap_navwalker()
        ]);

I've seen it suggested that I place this in a function and use an if statement to do something and on other pages, have this nav function. My problem is that I don't know what to put in the wp_nav_menu() for the custom post type pages, so it appears.

The URL for instance looks like: http://example.com/product-category/thing/

Topic navigation menus custom-post-types Wordpress

Category Web


You can just add these parameters in array variable and pass this to wp_nav_menu() Like:

function get_menu_params(){

    $defaults = array(
        'menu'              => 'Primary Menu',
        'theme_location'    => 'primary',
        'depth'             => 3,
        'container'         => 'div',
        'container_class'   => 'a',
        'container_id'      => 'b',
        'menu_class'        => 'nav navbar-nav',
        'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
        'walker'            => new wp_bootstrap_navwalker()
    );                          
    return $defaults;
}

and call it on the custom post type pages like below:

wp_nav_menu( get_menu_params( ) );

This will help you.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.