[wp-trac] [WordPress Trac] #57140: Add filters to allow themes and plugins to pass HTML attributes to different Nav Walker output

WordPress Trac noreply at wordpress.org
Thu Jun 22 21:13:17 UTC 2023


#57140: Add filters to allow themes and plugins to pass HTML attributes to
different Nav Walker output
-------------------------------------------------+-------------------------
 Reporter:  davidwebca                           |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  6.3
Component:  Menus                                |     Version:  3.0
 Severity:  minor                                |  Resolution:
 Keywords:  has-patch needs-testing has-unit-    |     Focuses:
  tests                                          |  javascript, template
-------------------------------------------------+-------------------------

Comment (by oglekler):

 @costdev,

 I did manual testing with Twenty Twenty theme and WP 6.3-alpha-55505-src
 with the following filters:


 {{{
 add_filter( 'nav_menu_submenu_attributes', function( $atts, $args, $depth
 ) {

     $atts['class']     = ! empty( $atts['class'] ) ? $atts['class'] . '
 57140-submenu_attributes-0' : ' 57140-submenu_attributes-0';
     $atts['data-test'] = '57140-submenu_attributes-1';

     return $atts;
 }, 10, 3);

 add_filter( 'nav_menu_item_attributes', function( $atts, $menu_item,
 $args, $depth ) {

     $atts['class']     = ! empty( $atts['class'] ) ? $atts['class'] . '
 57140-item_attributes-0' :  '57140-item_attributes-0';
     $atts['data-test'] = '57140-item_attributes-1';

     return $atts;
 }, 10, 4);

 add_filter( 'nav_menu_link_attributes', function( $atts, $menu_item,
 $args, $depth ) {

     $atts['class']     = ! empty( $atts['class'] ) ? $atts['class'] . '
 57140-link_attributes-0' : '57140-link_attributes-0';
     $atts['data-test'] = '57140-link_attributes-1';

     return $atts;
 }, 10, 4);
 }}}

 All attributes went into the correct places.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57140#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list