Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Losing page id's on li's for menu when there's multiple menus

Tags:

php

wordpress

I created a menu which I output on a page... each li of the menu had the page ID as an id allowing me to target specific li's.

When I added the 2nd and 3rd location for the same menu, all the id's disappeared so a lot of my styling messed up due to it no longer outputting the id's. How can I get these back when there's multiple menus?

I'm registering 3 menu locations using the following:

// Register our themes menu locations
function register_menus() {
    register_nav_menu('primary-menu', __('Primary Menu'));
    register_nav_menu('mobile', __('Mobile Menu'));
    register_nav_menu('products', __('Products Menu'));        
    register_nav_menu('footer-menu', __('Footer Menu'));
}
add_action('init', 'register_menus');

Assigning the same menu to the 3 locations:

enter image description here

Then outputting in my template with the following:

<?php if ( has_nav_menu( 'primary-menu' ) ) {
wp_nav_menu( array(
  'container'=>'div',
  'menu_class'=>'1',
  'theme_location' => 'primary-menu',
  'walker' => new CSS_Menu_Maker_Walker(),
  'items_wrap' => '<ul class="primary-menu-1">%3$s</li></ul>'
));
} ?>


<?php if ( has_nav_menu( 'mobile' ) ) {
  wp_nav_menu( array(
    'container'=>'div',
    'menu_class'=>'2',
    'theme_location' => 'mobile',
    'walker' => new CSS_Menu_Maker_Walker(),
    'items_wrap' => '<ul class="primary-menu-2">%3$s</li></ul>'
  ));
} ?>


<?php if ( has_nav_menu( 'products' ) ) {
  wp_nav_menu( array(
    'container'=>'div',
    'menu_class'=>'3',
    'theme_location' => 'products',
    'walker' => new CSS_Menu_Maker_Walker(),
    'items_wrap' => '<ul class="primary-menu-3">%3$s</li></ul>'
  ));
} ?>
like image 572
Rob Avatar asked Sep 05 '18 15:09

Rob


1 Answers

Adding 'menu'=>'my-class-name', to each menu instance brings them back.

like image 142
Rob Avatar answered Nov 09 '22 12:11

Rob