30th August, 2020
How to change WordPress sub-menu class
Sometimes you need to customize the default wordpress menu system to add your own set of css classes. WordPress provides a couple of filters to do that.
I use these code to add custom classes to list items and menu links in WordPress. Paste these in your functions.php file or your plugin file to make this work.
function ab_submenu_class($menu) { $menu = preg_replace('/ class="sub-menu"/','/ class="submenu" /',$menu); return $menu; } add_filter('wp_nav_menu','ab_submenu_class');
That’s it. Refresh your browser and see the changes.