1. Home
  2. WordPress
  3. APi Development
  4. cors problem fixed

cors problem fixed

add to your functions.php

function custom_cors_headers() {
    $allowed_origins = ['https://kreatech.ca', 'https://www.kreatech.ca'];

    if (isset($_SERVER['HTTP_ORIGIN']) && in_array($_SERVER['HTTP_ORIGIN'], $allowed_origins)) {
        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    }

    header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
    header("Access-Control-Allow-Credentials: true");
    header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
}
add_action('init', 'custom_cors_headers');

How can we help?