wp_nav_menu change sub-menu class name?

前端 未结 13 2028
自闭症患者
自闭症患者 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 03:10

    You can just use a Hook

    add_filter( 'nav_menu_submenu_css_class', 'some_function', 10, 3 );
    function some_function( $classes, $args, $depth ){
        foreach ( $classes as $key => $class ) {
        if ( $class == 'sub-menu' ) {
            $classes[ $key ] = 'my-sub-menu';
        }
    }
    
    return $classes;
    }
    

    where

    $classes(array) - The CSS classes that are applied to the menu <ul> element.
    $args(stdClass) - An object of wp_nav_menu() arguments.
    $depth(int) - Depth of menu item. Used for padding.
    
    0 讨论(0)
提交回复
热议问题