...
Wordpress

How to change sub-menu class name with wp_nav_menu?

07 January 2019

In WordPress, all sub-menus have the class ‘sub-menu'(sub-menu class name with wp_nav_menu). To change it to a custom class, add the following code in your functions.php file.

You can use WordPress preg_replace filter example:

For Example:
function new_submenu_class($menu) {    
    $menu = preg_replace('/ class="sub-menu"/','/ class="yourclass" /',$menu);        
    return $menu;      
}
add_filter('wp_nav_menu','new_submenu_class'); 
Output here:

sub-menu class name with wp_nav_menu

Leave a Comments