wp api - No 'Access-Control-Allow-Origin' when call rest API

admin2025-01-07  4

I am using ReactJs with WordPress. WordPress running on localhost 8888 port and React app running on 3000 port. When I change the WordPress site URL (from settings->general) to localhost:300 then I am getting the following error,

Access to XMLHttpRequest at 'http://localhost:8888/bolb/wp-json/wp/v2/categories' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

It's not working on the postman too. But, it's okay if I use the same URL (http://localhost:8888/bolb) as the site URL.

I am using ReactJs with WordPress. WordPress running on localhost 8888 port and React app running on 3000 port. When I change the WordPress site URL (from settings->general) to localhost:300 then I am getting the following error,

Access to XMLHttpRequest at 'http://localhost:8888/bolb/wp-json/wp/v2/categories' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

It's not working on the postman too. But, it's okay if I use the same URL (http://localhost:8888/bolb) as the site URL.

Share Improve this question asked May 11, 2020 at 4:25 Sonjoy DattaSonjoy Datta 1692 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

just write this on your function.php

add_filter( 'allowed_http_origin', '__return_true' );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736253079a97.html

最新回复(0)