Skip to content

Instantly share code, notes, and snippets.

@philliproth
Created May 7, 2021 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philliproth/5d3bdd05631d7ac72c80ebf92d94a85e to your computer and use it in GitHub Desktop.
Save philliproth/5d3bdd05631d7ac72c80ebf92d94a85e to your computer and use it in GitHub Desktop.
function wcag_nav_menu_link_attributes( $atts, $item, $args, $depth ) {
// Add [aria-haspopup] and [aria-expanded] to menu items that have children
$item_has_children = in_array( 'menu-item-has-children', $item->classes );
if ( $item_has_children ) {
$atts['aria-haspopup'] = "true";
$atts['aria-expanded'] = "false";
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'wcag_nav_menu_link_attributes', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment