wordpress walker add class to submenu a href

There are special filters for adding classes to the ul, li, or a tags in a menu.

For the a tags you want to use nav_menu_link_attributes. This allows you to modify all attributes on the a tag, so here’s an example:

function my_nav_menu_link_attributes( $atts, $item, $args ) {
    if ( 'main' === $args->theme_location ) {
        if ( '0' === $item->menu_item_parent ) {
            $atts['class'] = 'top-level-item';
        } 
    }
    return $atts;
}
add_filter( 'nav_menu_link_attributes', 'my_nav_menu_link_attributes', 10, 3 );