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;


That’s it. Refresh your browser and see the changes.

Leave a Reply

Your email address will not be published.