Remove Extraneous WordPress Class Names from Nav Menu Markup

WordPress adds a lot of CSS classes in nav menus. All of you perfectionists out there are probably looking for a good way of cleaning up the sheer number of class names generated.

For starters, WordPress outputs a number of backwards compatible class names that really aren’t needed, especially if you are creating your own theme. Then there are a number of dynamically generated class names that include the object type, menu item type and IDs.

I’ve written a function that will remove the extraneous class names that are rarely used:

The following is a list of the WordPress class names that will make it through the blacklist function above:

Of course, the blacklist will also allow any custom classes through; such as those added by a plugin or theme.

Leave a Reply

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