Removing Dropdown Class from Menu List

How do I remove the dropdown class from the navigation without removing it from my main navigation?

  register_nav_menus(array(
    'primary_navigation' => __('Primary Navigation', 'roots'),
    'category_accordion' => __('Category Accordion', 'roots'),
    'start_here' => __('Start Here', 'roots')
  ));

I’d like to remove start_here from having any dropdown classes.

I’m using this shortcode to display the menu on any page (easier for the client to use)

function print_menu_shortcode($atts, $content = null) {
	extract(shortcode_atts(array( 'name' => null, ), $atts));
		return wp_nav_menu( array( 'menu' => $name, 'echo' => true ) );
	}
add_shortcode('menu', 'print_menu_shortcode');

I suppose I could add a menu class in there but that’s only for the container and not for ul or li which is calling the dropdown.

Thansk!

You need to extend the Roots_Nav_Walker class, remove the logic for the dropdowns, and then pass it to wp_nav_menu in your shortcode as a new object.

Hm. I figured that but was kind of hoping there would be something easier. Seems like a whole lot of code to create another menu.

You could also add conditional checks to the pre-existing class; create a zero depth menu; or use the default WordPress walker.

This might help someone else who comes across this thread - to change a particular menu to revert to the default WP walker (maybe the easiest way to remove Bootstrap dropdown data attributes and just list links inline) see following code (the last argument to the wp_nav_menu function sets the walker to the default):

<?php
              if (has_nav_menu('start_here')) :
                wp_nav_menu(array('theme_location' => 'start_here', 'menu_class' => 'list-inline', 'walker' => new Walker_Nav_Menu));
              endif;
            ?>
3 Likes