wp_nav_menu change sub-menu class name?

前端 未结 13 2102
自闭症患者
自闭症患者 2020-11-28 02:44

Is there a way to change the child

    generated by WordPress itself to a custom class name?

    I know the parent

13条回答
  •  渐次进展
    2020-11-28 02:51

    There is no option for this, but you can extend the 'walker' object that WordPress uses to create the menu HTML. Only one method needs to be overridden:

    class My_Walker_Nav_Menu extends Walker_Nav_Menu {
      function start_lvl(&$output, $depth) {
        $indent = str_repeat("\t", $depth);
        $output .= "\n$indent
      \n"; } }

    Then you just pass an instance of your walker as an argument to wp_nav_menu like so:

    'walker' => new My_Walker_Nav_Menu()
    

提交回复
热议问题