Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge two menu managed separately in wordpress for displaying as one in front end theme?

I am working on a wp theme for a site which is already built on wp, and having very large menu which is divided into two menu in wp admin.

I want to merge this two menu in theme in single UL. Currently it generates two menu in different div container and ul li, and is breaking the styles & js applied on it.

How can i merge this two menu into single ul li in single container?

like image 793
Krunal Avatar asked Apr 27 '12 07:04

Krunal


People also ask

Is it possible to combine more than 2 WordPress themes?

Is it possible to combine / merge more then 2 WordPress themes and make change look so it feels like one single website and users can still access all the features and functions seamlessly? Show activity on this post. Yes, It's possible but it will cost you a lot of time and effort.

How to add duplicate menu in WordPress with one click?

Click on Duplicate Menu button and you are done. Now you can visit Appearance » Menus, and you can select your duplicate menu from the drop down menus. We hope this article helped you add a duplicate menu in WordPress with just one click.

Which WordPress theme has all 3 features in one theme?

No single WordPress theme is offering all 3 features in one theme. We thought to buy one theme for listing, one for events and one for articles and somehow make one website.

What is flatsome WordPress theme?

Flatsome is a multipurpose WordPress theme with over 38,000 sales on ThemeForest. This theme uses a top-bar menu on top of a traditional navigation menu. The demo uses the main navigation menu to link to the site’s most important pages, such as the Shop and Blog pages.


2 Answers

You can combine them with this method. It keeps some of the menu classes generated 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>',
) );
like image 68
alexwc_ Avatar answered Nov 16 '22 02:11

alexwc_


The problem is that each wp_nav_menu is still being wrapped in individual div's. You need to turn off those div's as well, by adding "'container' => false" to each one, like so:

<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>
like image 38
skladany Avatar answered Nov 16 '22 02:11

skladany