John Davidson

php - Enable Cors on WordPress

0 comments
Message:


I have a site with WordPress using WooCommerce, that I want to make as api for my React app..


I have understand that I need to add some Code Lines at the server code (wp content).
But I didn't understand which is code in which file of the server??


I have seen a lot of functions that "I need to put in my Functions.php" but none of them take care of the problem..


Someone can help me?
what is the missing code?
where do I paste it?
What I do wrong?


The files



My Answer:
can be used to enable CORS in WordPress, but the most common method is to add the following code to your theme's functions.php file:

php
function add_cors_http_header(){
header("Access-Control-Allow-Origin: *");
}
add_action('init','add_cors_http_header');


This code will add the necessary CORS headers to your WordPress site, allowing your React app to make requests to it. Just add this code to your theme's functions.php file and you should be good to go.

Rate this post

4 of 5 based on 3906 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us