How to combine two menus managed separately in wordpress to display as one in the front-end theme?

I am working on a wp theme for a site that is already built on wp and has a very large menu that is divided into two menus in the wp admin.

I want to combine these two menus in a theme in one UL. It currently generates two menus in different containers div and ul li and breaks down the styles and js applied to it.

How can I combine these two menus into one ul li in one container?

+5
source share
3 answers

ok, so if you use wp_nav_menu ()

try using something like

<ul id="MyMenu">
  <?php wp_nav_menu( array('menu' => 'FirstMenu', 'items_wrap' => '%3$s' ) ); ?>
  <?php wp_nav_menu( array('menu' => 'SecondMenu', 'items_wrap' => '%3$s' ) ); ?>
</ul>

using items_wrap will remove ul from each menu, so encapsulate the menu in an already defined ul tag, wp_nav_menu will spit out only li tags.

. ul: http://codex.wordpress.org/Function_Reference/wp_nav_menu

M

+13

, wp_nav_menu div. div, "'container' = > false" :

<ul id="MyMenu">
  <?php wp_nav_menu( array('menu' => 'FirstMenu', 'items_wrap' => '%3$s', 'container' => false ) ); ?>
  <?php wp_nav_menu( array('menu' => 'SecondMenu', 'items_wrap' => '%3$s', 'container' => false ) ); ?>
</ul>
+9

You can combine them with this method. It stores some menu classes created by WP.

// two WordPress menus combined into one.
// first menu.
$menu = wp_nav_menu( array(
    'theme_location'=> 'secondary', // or whatever location
    'fallback_cb'   => false,
    'container'     => '',
    'items_wrap' => '%3$s',
    'echo' => false
) );
// include all of the menu items from the first inside the second menu.
wp_nav_menu( array(
    'theme_location' => 'primary', // or whatever location
    'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s ' . $menu . '</ul>',
) );
0
source

All Articles