plugins - Multiple navigation menus to a location?

admin2025-01-07  4

I want to be able to assign multiple menu's to 1 navigation location.

But when I want to assign the second navigation, the previous is unassigned.

How would it be possible without breaking the Wordpress core files?

This is what I am aiming for: How can I display a menu on certain pages only?

I want to be able to assign multiple menu's to 1 navigation location.

But when I want to assign the second navigation, the previous is unassigned.

How would it be possible without breaking the Wordpress core files?

This is what I am aiming for: How can I display a menu on certain pages only?

Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Apr 21, 2015 at 14:02 user40422user40422 2
  • Would the menus then display one after the other? What end result are you aiming for? – TheGentleman Commented Apr 21, 2015 at 15:55
  • I am building a plugin like this. Problem is, I can't assign multiple menu's to a single location. My plugin desides what menu to load on which page. – user40422 Commented Apr 22, 2015 at 7:27
Add a comment  | 

1 Answer 1

Reset to default 0

is this look like the menu you aiming ?

Here how to create it

Create custom menu in your functions.php ,

// main menu
function main_nav()
{
wp_nav_menu(
array(
    'theme_location'  => 'header-menu',
    'menu'            => '',
    'container'       => 'div',
    'container_class' => '',
    'container_id'    => '',
    'menu_class'      => 'menu',
    'menu_id'         => '',
    'echo'            => true,
    'fallback_cb'     => 'wp_page_menu',
    'before'          => '',
    'after'           => '',
    'link_before'     => '',
    'link_after'      => '',
    'items_wrap'      => '<ul>%3$s</ul>',
    'depth'           => 0,
    'walker'          => ''
    )
);
}

// Extra menu
function menu_extra_nav()
{
wp_nav_menu(
array(
    'theme_location'  => 'extra-menu',
    'menu'            => '',
    'container'       => 'div',
    'container_class' => '',
    'container_id'    => '',
    'menu_class'      => 'menu',
    'menu_id'         => '',
    'echo'            => true,
    'fallback_cb'     => 'wp_page_menu',
    'before'          => '',
    'after'           => '',
    'link_before'     => '',
    'link_after'      => '',
    'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    'depth'           => 0,
    'walker'          => ''
    )
);
}

Create Main Menu and Extra Menu in Apparances > Menus

Then add the menu to your desired location, example I put on main nav header

<nav class="nav" role="navigation">
    <?php main_nav(); ?>
    <?php menu_extra_nav(); ?>
</nav>

Then define main and extra menu in your Apparances > Themes > Customize > Navigation

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736255255a267.html

最新回复(0)