How to call different menus in header.php in WordPress

I want to show different menus for different templates. For example if the user is in any page i want to show one menu, if user is in post category i want to show another menu, if the user in single.php page i want to show another menu. How to do it ?

I know about creating multiple header(and these headers show different menu) in the theme and calling these header in different templates. But i want to do it simply though if else statement in my header.php itself. How to do it?

Read More

My header.php menu code is –

                        <div id="navbar" class="navbar-collapse collapse">
                             <?php
                                wp_nav_menu( array(
                                    'menu'              => 'primary',
                                    'theme_location'    => 'header-menu',
                                    'depth'             => 2,
                                    'container'         => 'div',
                                    'container_class'   => '',
                                    'container_id'      => '',
                                    'menu_class'        => 'nav navbar-nav',
                                    'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
                                    'walker'            => new wp_bootstrap_navwalker())
                                );
                            ?>
                        </div>

i want to do an if else statement in the header.php itself like –

<div id="navbar" class="navbar-collapse collapse">
    if(template is page)
    {
        //menu code 1
    }
    else (template is category)
    {
        //menu code 2
    } 
</div>

Please help ?

Related posts

Leave a Reply

1 comment