WordPress cross domain issues

I’m having issues with ..Cross-Origin Resource Sharing policy: The 'Access-Control-Allow-Origin' header..

The site runs on 3 different domains using the WPML plugin for 3 different languages. The references to e.g. the stylesheet URL point to 1 URL (the main domain) which means that 2 of the sites are requesting info cross domain and this is causing fonts not to load.

Read More

I’m hoping to solve this by removing the protocal and domain from the stylesheet URL’s, so that it’s pointing to a ‘relative’ path to the files (e.g. /wp-content/themes/salient/style.css?ver=4.8.1)

Is there a way to change this in WordPress? Doesn’t just have to be for the stylesheet, it can be for all the files that are referenced by WordPress.

Related posts

Leave a Reply

1 comment

  1. You can allow resources to be loaded from sub domain by adding following line to your .htaccess file

    Load resources from sub-domain:

    # Allow font, js and css to be loaded from subdomain
    SetEnvIf Origin "http(s)?://(.+.)?(example.com)$" ORIGIN_DOMAIN=$0
    <IfModule mod_headers.c>
        <FilesMatch ".(eot|font.css|otf|ttc|ttf|woff|js|png|jpg|jpeg|gif)$">
            Header set Access-Control-Allow-Origin %{ORIGIN_DOMAIN}e env=ORIGIN_DOMAIN
        </FilesMatch>
    </IfModule>
    

    Load resources from all other domains:

    # Allow font, js, and css to be loaded from subdomain
    <IfModule mod_headers.c>
        <FilesMatch ".(eot|font.css|otf|ttc|ttf|woff|js|png|jpg|jpeg|gif)$">
            Header set Access-Control-Allow-Origin "*"
        </FilesMatch>
    </IfModule>
    

    Source: http://www.webspeaks.in/2015/01/wordpress-allow-cross-domain-resources.html