Add a custom class to nav li item

You code is working for me with (and without) some modifications on your code, to place in functions.php :

add_filter( 'nav_menu_css_class', 'menu_item_classes', 10, 4 );

function menu_item_classes( $classes, $item, $args, $depth ) {

    unset($classes);

    $classes[] = 'current-menu-ancestor';

    return $classes;
}

If it’s still not working, verify that your are working on the right theme_location id in wp_nav_menu().

Hope it helps !