Skip to content

Instantly share code, notes, and snippets.

@dtateii
Created September 29, 2017 15:24
Show Gist options
  • Save dtateii/288c39d27d79f4847b4dc53064c83b2a to your computer and use it in GitHub Desktop.
Save dtateii/288c39d27d79f4847b4dc53064c83b2a to your computer and use it in GitHub Desktop.
Q+D CORS headers for WP REST API
<?php
/**
* Plugin Name: CORS
* Description: Just adds headers to every response to enable cross-origin GET requests for API.
* Version: 0.0.1
* Author: NJI Media
* Author URI: https://www.njimedia.com
* License: GPLv2 or later
* Text Domain: cors
*
* @package WordPress
* @subpackage CORS
*/
// Hook in.
add_action( 'init', 'add_cors_headers' );
/**
* Add CORS headers to all responses.
*/
function add_cors_headers() {
header( 'Access-Control-Allow-Origin: *' );
header( 'Access-Control-Allow-Methods: GET' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment