I want to remove some specific class names from the menu items
For example I need to remove classes of fa and fa-desktop from all menu items in WordPress

<li id="menu-item-21" class="dropdown-header fa fa-desktop menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children dropdown col-sm-4 menu-col menu-item-21 dropdown">

Thank you

  • 2
    custom walker class? do share walker class here. it will be easy to understand your situation and you can get better help.
    – Anwer AR
    Commented May 22, 2017 at 20:18
  • @AbdulRehman can you check my next answer? I used this Commented May 22, 2017 at 20:42

1 Answer 1

add_filter('nav_menu_css_class', 'special_nav_class', 10, 2);
function special_nav_class($classes, $item){
    if(($key = array_search('fa', $classes)) !== false) {
    return $classes;
  • This is not a walker, it's a filter. Also, "fa fa-desktop" are not built-in classes, they're being added by something else - perhaps you're using Font Awesome or some kind of plugin that is adding them. Could you please share your code where you actually call wp_nav_menu? Also - it's better to use the "edit" link to adjust your question rather than adding more question details as an answer. :)
    – WebElaine
    Commented May 23, 2017 at 13:44
  • @WebElaine this fixed my problem, forget walker :) Commented May 23, 2017 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.