0

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/

  • If you've verified that the function is present but outputs nothing, the likely culprit is some poorly targeted code modifying the query for menu items causing nothing to be returned. – Milo May 8 '17 at 12:50
0

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.

  • I probably miscommunicated. This I get. The nav menu displays on everything but custom post type archive pages. wp_get_nav_menu_object also returns null. I can get an Add Menu link where the nav should be, but that is it. – nobrandheroes May 8 '17 at 17:42
  • Then I Think may be issue is with these two parameters, 'fallback_cb' => 'wp_bootstrap_navwalker::fallback', 'walker' => new wp_bootstrap_navwalker() Check it by removing these two parameters – Baikare Sandeep May 9 '17 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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