• Hi there

    We want to create some snippets on a website that uses different site and home urls. When trying to save a snippet, we get a network error and such a message in the console:

    Access to XMLHttpRequest at 'https://***/wp-json/code-snippets/v1/snippets' from origin 'https://admin.***' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

    With no other plugins such as WooCommerce did we have any issues with that setup. Is there a way to get your plugin working with this setup without changing the CORS policy?

    Thanks a lot!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Shea Bunge


    It sounds like this might be an issue with the WordPress REST API – either with out specific endpoints, or the way it deals with CORS issues on separate URLs in general.

    I’ll do some testing and see if I can come up with a solution.

    Thread Starter weitblickonline


    Thanks for looking into it.

    In the mean time, we found a partial workaround. Importing snippets and then activating them works. However, changing a snippet is still not possible.

    Because you mentioned the API: Sometimes it is an indication for problems with the API if wp-json does not return a result. In our case, however, https://***/wp-json works fine with both URLs.

    If I can help, feel free to let me know.

    Plugin Author Shea Bunge


    I’m not sure if I understand you correctly, but are you saying that the REST API can be accessed by both URLs?

    If so, I wonder if you could solve this by changing the request URL WordPress uses. Something like:

    	function ( $url, $path, $blog_id, $scheme ) {
    		return 'rest' === $scheme ?
    			'https:///admin.example.com/wp-json' . $path :
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘CORS policy when having a different backend URL’ is closed to new replies.