允许WordPress Rest API 跨域访问

// 允许WordPress Rest API 跨域访问:
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 );