Snippet: Remove or replace one ore more classes from wordpress menu

Add following snippet to “functions.php”

Snippet

add_filter('wp_nav_menu', 'wpds_wp_nav_menu');
function wpds_wp_nav_menu($text) {
  $replace = array(
    'current-menu-item'     => 'current',
    'sub-menu' => '',
  );

  $text = str_replace(array_keys($replace), $replace, $text);
  return $text;
}

Result

“sub-menu” class is removed from the generated navigation and “current-menu-item” class will be replaced with “current”.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>