Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Menu drop-down and aria labels

  • I am receiving the following accessibility errors for the astra primary menu:

    Menu dropdowns should be tagged for assistive technology.
    Menu items that have a dropdown should include an aria-haspopup=”true” attribute.
    Code snapshots of failed elements
    <a href="https://timberlinemtguides.com/trip_location/ski-mountaineering/" >Ski Mountaineering<span role="presentation" class="dropdown-menu-toggle" ></span></a>

    Dropdown expanded/collapsed state should be represented in the code.
    Menu items that have a dropdown should include an “aria-expanded” attribute set to “false” by default, which changes to “true” when the dropdown is opened, and back to “false” when closed.
    Code snapshots of failed elements
    <a href="https://timberlinemtguides.com/trip_location/ski-mountaineering/" >Ski Mountaineering<span role="presentation" class="dropdown-menu-toggle" ></span></a>

    Are there ways that I can address this? Or is this something that GeneratePress has to update?
    I’m using the WordPress menu in GP’s header.

  • Hi there,

    Adding this snippet should resolve the accessibility error in your case:

    function add_aria_expanded_attribute( $atts, $item, $args, $depth ) {
        // Check if the current menu item has children
        if ( in_array( 'menu-item-has-children', $item->classes ) ) {
            // Add the aria-expanded=false attr
            $atts['aria-expanded'] = 'false';
            $atts['aria-haspopup'] = 'true';
        }
        return $atts;
    }
    add_filter( 'nav_menu_link_attributes', 'add_aria_expanded_attribute', 10, 4 );

    Adding PHP: https://docs.generatepress.com/article/adding-php/

  • Thanks that worked.

    Is this something that will be included in future releases?

    Moving forward, do I need to look to update this inserted code to accommodate possible future changes to accessibility standards?

  • Accessibility improvement is something we are actively working on in the theme, and we are exploring the best ways to accommodate these changes.

    For now, you can use the snippet, and any future changes will definitely be communicated to our users.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.