noindex for direct links to URLs with facets when using Yoast SEO

/** Experimental, use at your own risk. Test thoroughly to not mess up your SEO
 ** uses wpseo_robots from Wordpress Seo plugin (Yoast) to change direct links
 ** for facet pages with facets in url from index to noindex in robots meta tag.
 ** Note: Yoast removes the canonical link for page URLs with noindex.

add_filter( 'wpseo_robots', function( $robots ) {
    if ( function_exists( 'FWP' ) && ! FWP()->request->is_refresh && !empty( FWP()->request->url_vars )  ) {
        return str_replace( 'index', 'noindex', $robots);
    return $robots;