Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Aleix-Marti's full-sized avatar

Aleix Martí Carmona Aleix-Marti

View GitHub Profile
Aleix-Marti / functions.php
Created February 2, 2024 07:52
PWA - Headless WP
// Para evitar problemas de CORS con las peticiones entre dominios distintos
add_action('init', 'handle_preflight');
function handle_preflight() {
$origin = get_http_origin();
if ($origin === '') {
header("Access-Control-Allow-Origin: midominio");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Credentials: true");
header('Access-Control-Allow-Headers: Origin, X-Requested-With, X-WP-Nonce, Content-Type, Accept, Authorization');