When your website means business.

Nav Menu, WordPress | Type: PHPAdd attributes to WordPress Nav Menu Links (a tag)

This can be very useful if you need to add attributes for a menu script.

/**
* Add custom attribute and value to a nav menu item's anchor based on CSS class (for MetisMenu)
* @author Sridhar Katakam
* @link https://sridharkatakam.com/
*/
add_filter( 'nav_menu_link_attributes', function ( $atts, $item, $args ) {
    if ( 'open' === $item->classes[0] ) {
        $atts['aria-expanded'] = 'false';
    }
    if ( 'open' === $item->classes[0] ) {
        $atts['class'] = 'has-arrow';
    }
    return $atts;
}, 10, 3 );

Reference Links