remove li class & id for menu items and pages list

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

Example of WordPress default CSS class output:

  • &l
  • 8条回答
    •  北海茫月
      2021-01-30 23:59

      this is an addition on top of Richard answer.

      in case you want to change the current-menu-item class to something else.

              add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1);
              add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1);
              function my_css_attributes_filter($var) {
                  if(is_array($var)){
                      $varci= array_intersect($var, array('current-menu-item'));
                      $cmeni = array('current-menu-item');
                      $selava   = array('selectedmenu');
                      $selavaend = array();
                      $selavaend = str_replace($cmeni, $selava, $varci);
                  }
                  else{
                      $selavaend= '';
                  }
              return $selavaend;
              }
      

    提交回复
    热议问题