How to add custom class in WordPress menu hyperlink tag

Simply add this code in functions.php

function dandd_menu_add_class( $atts, $item, $args ) {
    $class = ‘nav-link’;
    $atts[‘class’] = $class;
    return $atts;
}
add_filter( ‘nav_menu_link_attributes’, ‘dandd_menu_add_class’, 10, 3 );