1

I'm trying to enable CORS in wordpress and I've placed this line of code in my header.php file

header("Access-Control-Allow-Origin: *");

Then I tested to see if it works via this page http://client.cors-api.appspot.com/client

The response I get is:

Fired XHR event: loadstart
Fired XHR event: readystatechange
Fired XHR event: error

XHR status: 0
XHR status text: 
Fired XHR event: loadend

I'm not sure what I'm doing wrong here, anybody able to help me out?

Thanks

1

Headers manipulation should be done before template output starts. In WordPress it is typically done in template_redirect hook, which is right before template load but after core has fully loaded.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.