Remove li class & ID from wp_nav_menu

Webmaster WordPress Leave a Comment

Removes the li class & ID from wp_nav_menu

Place the code below into your themes functions.php file between the <?php.

// Removes li classes & ID’s from wp_nav_menu

add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1);
add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1);
add_filter('page_css_class', 'my_css_attributes_filter', 100, 1);
function my_css_attributes_filter($var) {
  return is_array($var) ? array() : '';
}

// Removes particular classes & ID’s from wp_nav_menu

function my_css_attributes_filter($var) {
  return is_array($var) ? array_intersect($var, array('current-menu-item')) : '';
}

Leave a Reply

Your email address will not be published. Required fields are marked *