Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* Plugin Name: WP REST API - Allow All CORS Requests
* Description: Adds headers to allow cross-origin requests to the WordPress REST API.
* Version: 1.0
* Plugin URI:
* Author: Micah Wood
* Author URI:
add_action( 'rest_api_init', function() {
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: POST, GET, OPTIONS, PUT, DELETE' );
header( 'Access-Control-Allow-Credentials: true' );
return $value;
}, 12 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.