When your website means business.

Nav Menu, WP/CP | 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

We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.