2

In my theme i need to display different left side menus on different pages. so i register a secondary menu too by this

register_nav_menus(
    array(
      'primary' => __( 'Top Menu' ),
      'left' => __( 'Left Menu' )
    )
  );

and i used a plugin named CE WP-Menu per Page to select menus from dropdown list shown in the page edit, so that i can assign different menu for different pages. and in my page template i wrote the below code to display the menus

wp_nav_menu( array( 'container' => false, 'menu_id' => 'menu-left-side-menu', 'menu_class' => 'menu', 'theme_location' => 'left' ) );

In Dashboard->Appearnce->menus i have created 3 menus (for test, actually no: of menus depends on no: of pages created). They are

1.top menu
2. left menu1
3. left menu2

and had assigned primary for top menu and left for left menu1. everything worked perfectly. but i have to assign left menu2 for another page and display it. for that when i assign left menu2 to location left , previous assignement of left menu1 overwrites. and now left menu1 is not showing in the page.

Problem

Is there any way to make the wordpress menu supports assigning more than one menus to same menu theme location??

I hope my problem description is understandable. if any clarification needed please tell me.

  • Why do you want to do that. You can simply add as many menu as you want in a single container for further CSS styling. – Robert hue Nov 5 '14 at 10:33
  • I need to display different set of menus for each page. that is page1 should show menu1 , page2 should show menu2 and so on. but all these menus must be displayed in same div location. if i create different theme locations separate for each menu then it will be numerous. thats why i thought of this method. if you know a better way to solve my issue please share it with me. – Zammuuz Nov 5 '14 at 10:37
1

You can use conditional is_page to define different menu items as you want.

if ( is_page( 'About' ) ) {

    wp_nav_menu( array( 'container' => false, 'menu_id' => 'menu-left-side-menu', 'menu_class' => 'menu', 'theme_location' => 'about-page' ) );

} elseif ( is_page( 'Services' ) ) {

    wp_nav_menu( array( 'container' => false, 'menu_id' => 'menu-left-side-menu', 'menu_class' => 'menu', 'theme_location' => 'services-page' ) );

} elseif ( is_page( 'Contact' ) ) {

    wp_nav_menu( array( 'container' => false, 'menu_id' => 'menu-left-side-menu', 'menu_class' => 'menu', 'theme_location' => 'contact-page' ) );

} else {

    wp_nav_menu( array( 'container' => false, 'menu_id' => 'menu-left-side-menu', 'menu_class' => 'menu', 'theme_location' => 'default-menu' ) );

}

And you can define as many menu as you want in your theme.

register_nav_menus(
    array(
        'about-page' => __( 'About Page Menu' ),
        'services-page' => __( 'Services Page Menu' ),
        'contact-page' => __( 'Contact Page Menu' ),
        'default-page' => __( 'Default Page Menu' ),
        'left' => __( 'Left Menu' )
    )
);

If you don't want to use many menus then you can simply add all items in one single menu and hide non-required menu items on each page with the help of WordPress body classes and CSS styles.

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.