Created
April 4, 2020 15:19
-
-
Save tarex/f53fffb1b83248f3ffff87c8c59ca3f4 to your computer and use it in GitHub Desktop.
WP Rest API Cors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add_custom_headers() { | |
add_filter( 'rest_pre_serve_request', function( $value ) { | |
header( 'Access-Control-Allow-Headers: Authorization, X-WP-Nonce,Content-Type, X-Requested-With'); | |
header( 'Access-Control-Allow-Origin: *' ); | |
header( 'Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE' ); | |
header( 'Access-Control-Allow-Credentials: true' ); | |
return $value; | |
} ); | |
} | |
add_action( 'rest_api_init', 'add_custom_headers', 15 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment