remove li class & id for menu items and pages list

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

Example of WordPress default CSS class output:

  • &l
  • 相关标签:
    8条回答
    • 2021-01-31 00:12

      If you just want to remove all the list classes and id's, add this to functions.php

      add_filter('nav_menu_item_id', 'filter_menu_id');
      add_filter( 'nav_menu_css_class', 'filter_menu_li' );
      function filter_menu_li(){
          return array('');   
      }
      function filter_menu_id(){
          return; 
      }
      
      0 讨论(0)
    • 2021-01-31 00:12

      An addition to Richard's answer: We need to clean up the empty classes left behind:

      //Strip Empty Classes
      add_filter ('wp_nav_menu','strip_empty_classes');
      function strip_empty_classes($menu) {
          $menu = preg_replace('/ class=(["\'])(?!active).*?\1/','',$menu);
          return $menu;
      }
      
      0 讨论(0)
    提交回复
    热议问题