remove li class & id for menu items and pages list

后端 未结 8 1401
青春惊慌失措
青春惊慌失措 2021-01-30 23:24

Example of WordPress default CSS class output:

  • &l
  • 8条回答
    •  孤独总比滥情好
      2021-01-30 23:52

      You should be able to remove them by hooking into a couple of filters and returning empty arrays or strings rather than new classes or ids:

      add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1);
      add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1);
      add_filter('page_css_class', 'my_css_attributes_filter', 100, 1);
      function my_css_attributes_filter($var) {
        return is_array($var) ? array() : '';
      }
      

      If you wanted to keep particular classes you could do something like this:

      function my_css_attributes_filter($var) {
        return is_array($var) ? array_intersect($var, array('current-menu-item')) : '';
      }
      

    提交回复
    热议问题