facetwp redirect on refresh

<?php
/** adds script to header 
 **/
add_action( 'wp_head', function() { ?>
	<script>
		(function($) {
        $(document).on('facetwp-refresh', function() {
            if (FWP.loaded && 'recipes' != FWP_HTTP.uri) { // if not the initial pageload, and we're on the homepage
                window.location.href = '/recipes/?' + FWP.buildQueryString(); // redirect
            }
        });
    })(jQuery);
	</script>
<?php } );