Sharing some useful tips, solutions and notes for Geeks.

Thursday, August 27, 2020

No Access-Control-Allow-Origin header is present on the requested resource issue Wordpress

There will come situations like we need to make ajax request to some other domains with wordpress and we face issue related to it.

When you make request, you will get issue like below in the console:

Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

This is because of the No Access Control Allow Orgin settings we have in the main site. We can solve this by adding fix in apache, in .htaccess or via filter in functions file. 

add_filter( 'allowed_http_origins', 'add_allowed_origins' );

function add_allowed_origins( $origins ) {

    $origins[] = '';

    $origins[] = '';

    return $origins;


Adding above filter will help recognize the requested URL is a valid one and ready to fullfil the ajax request. Hurray !!!!!

No comments: