Diagnosis

Theme replaces current menu item classes with ‘active’ class

16

Some theme strip out core menu classes like the current-menu-item classes and replace them with their own ‘active’ class. This forces the menu open on page load.

Themes should not be stripping out core WordPress classes that other plugins rely on.

Here is more information on Theme Interference

Background

The core WordPress menu system determines the current menu item status of each menu (meaning which item is pointing to the currently viewed page). It adds three standard classes:

current-menu-item
current-menu-parent
current-menu-ancestor

See: WordPress Menu Item CSS Classes

Some themes try to replace these classes with just active. It’s nice to try to simplify, but when it alters core functionality that other plugins depend on, it causes problems.

Identifying the problem

Generally, if a single submenu opens by default when its parent item is current (and you haven’t enabled that as an UberMenu setting), this is the cause. You can confirm by checking the markup and looking for the ubermenu-active class on that menu item (the theme will add the active class, but UberMenu automatically prefixes it with ubermenu-).

Most of the time, this issue occurs when a theme or plugin adds a filter to the nav_menu_css_class hook. Here’s an example:

function roots_nav_menu_css_class($classes, $item) {
  $slug = sanitize_title($item->title);
  $classes = preg_replace('/(current(-menu-|[-_]page[-_])(item|parent|ancestor))/', 'active', $classes);
  $classes = preg_replace('/^((menu|page)[-_\w+]+)+/', '', $classes);
  $classes[] = 'menu-' . $slug;
  $classes = array_unique($classes);
  return array_filter($classes, 'is_element_empty');
}
add_filter('nav_menu_css_class', 'roots_nav_menu_css_class', 10, 2);

This can also occur if a theme manipulates the output of the wp_nav_menu function, via the `wp_nav_menu` filter or directly in the theme templates, replacing string with str_replace or preg_replace. This is very bad practice.

Note that if the class names appear in the page source, but not in the DevTools, it indicates that they have been removed via javascript (this is very uncommon).

The Solution

UberMenu 3 Setting

In UberMenu 3, there is a setting in the Control Panel > General Settings > Miscellaneous > Disable Menu Item Class Filtering.

If the classes are being filtered via the nav_menu_css_class filter, this should resolve it.

preg_replace or str_replace

If the theme is running string replacement on the menu output, it is best that you just replace the theme’s menu system with Manual Integration.

Javascript

If your theme is removing the classes via javascript, this would need to be resolved either by removing that javascript, or altering the menu markup to prevent that JS from applying to UberMenu.