WordPress.org

Make WordPress Core

Opened 3 months ago

Last modified 3 months ago

#52694 new defect (bug)

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

Reported by: domainsupport Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Bundled Theme Keywords: has-patch
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 (3)

#1 @mukesh27
3 months 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 months ago

  • Keywords has-patch added

#3 @mukesh27
3 months ago

Ping @poena for thoughts and progress for this ticket.

Note: See TracTickets for help on using tickets.