Make WordPress Core

Opened 3 years ago

Last modified 18 months ago

#52694 new defect (bug)

Twenty Twenty-One: Primary menu toggle filter adds toggles to third party menu locations

Reported by: domainsupport's profile domainsupport Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Bundled Theme Keywords:
Focuses: Cc:

Description

The code in /inc/menu-functions.php ...

<?php
function twenty_twenty_one_add_sub_menu_toggle( $output, $item, $depth, $args ) {
        if ( 0 === $depth && in_array( 'menu-item-has-children', $item->classes, true ) ) {

                // Add toggle button.
                $output .= '<button class="sub-menu-toggle" aria-expanded="false" onClick="twentytwentyoneExpandSubMenu(this)">';
                $output .= '<span class="icon-plus">' . twenty_twenty_one_get_icon_svg( 'ui', 'plus', 18 ) . '</span>';
                $output .= '<span class="icon-minus">' . twenty_twenty_one_get_icon_svg( 'ui', 'minus', 18 ) . '</span>';
                $output .= '<span class="screen-reader-text">' . esc_html__( 'Open menu', 'twentytwentyone' ) . '</span>';
                $output .= '</button>';
        }
        return $output;
}
add_filter( 'walker_nav_menu_start_el', 'twenty_twenty_one_add_sub_menu_toggle', 10, 4 );

... should be updated so it doesn't affect third party menu locations.

Perhaps by using ...

<?php
if (isset($args->theme_location) && $args->theme_location === 'primary') {
...
}

Thank you.

Oliver

Change History (5)

#1 @mukesh27
3 years ago

I like the approach of @domainsupport. We can marge theme location condition in if statement like below.

if ( isset( $args->theme_location ) && 'primary' === $args->theme_location && 0 === $depth && in_array( 'menu-item-has-children', $item->classes, true ) ) {

This ticket was mentioned in PR #1066 on WordPress/wordpress-develop by mukeshpanchal27.


3 years ago
#2

  • Keywords has-patch added

#3 @mukesh27
3 years ago

Ping @poena for thoughts and progress for this ticket.

#4 @poena
18 months ago

Hi @mukesh27, do you want to create a new pull request?

#5 @poena
18 months ago

  • Keywords has-patch removed
Note: See TracTickets for help on using tickets.