0

I have a subdomain on my WP site that's loading a page and it has a Contact Form 7 form, that's posting data to my main domain. Since I got a CORS alert, tried the following:

function my_customize_rest_cors() {
    if( isset($_SERVER['REQUEST_URI']) && !is_bool(strpos($_SERVER['REQUEST_URI'], "careers.mysite.com") ) ){
        remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
        add_filter( 'rest_pre_serve_request', function( $value ) {
            header( 'Access-Control-Allow-Origin: *' );
            header( 'Access-Control-Allow-Methods: GET, POST, PUT' );
            header( 'Access-Control-Allow-Credentials: true' );
            header( 'Access-Control-Expose-Headers: Link', false );
            return $value;
        });
    }
}
add_action( 'rest_api_init', 'my_customize_rest_cors', 15 );

So, I check if the domain is this subdomain, and enable CORS. But I'm still getting the same error message.

Any suggestions?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.