How to enable CORS in WordPress
Time needed: 3 minutes.
There are numerous options to enable CORS, but the easiest approach is to use a basic custom function. Instructions for how to enable CORS in WordPress are below:
- Use a custom function, fastest way to enable CORS in WordPress:
function add_cors_http_header(){
header(“Access-Control-Allow-Origin: *”);
}
add_action(‘init’,’add_cors_http_header’);
Be sure not to use any combinations of these ( .htaccess, header.php, api.php, functions.php ) as it will cause redirect and/or critical errors. - QA the site
Be sure to QA client sites on 2 devices, at minimum (multiple networks are preferred).