How can I add Access-Control-Allow-Origin: * to the header for my Podlove feed?
There is no special hook for feeds, but you should be able to hook into core hooks like wp
. Example:
add_action('wp', function() {
// skip if it's not a podlove feed
if (!$feed = \Podlove\Feeds\get_feed())
return;
// set custom headers
header('...');
});
Itâs not working for me.
I added this to my custom functions list:
add_action('wp', function() {
// skip if it's not a podlove feed
if (!$feed = \Podlove\Feeds\get_feed())
return;
// set custom headers
header("Access-Control-Allow-Origin: *");
});
but I still get, âAccess ⌠has been blocked by CORS policy: No âAccess-Control-Allow-Originâ header is present on the requested resource.â
I thought it might be the wildcard, so I tried this instead: header(âAccess-Control-Allow-Origin: âGETââ);
Still didnât work.
I temporarily changed themes to the Twenty-twenty built-in theme, just to make sure there wasnât something in my theme causing the issue, and I pasted the above code into that themeâs functions.php file, but it didnât work that way either.
What am I doing wrong?
My feed URL is: https://www.loatoday.net/feed/mp3
Maybe this plugin works for you https://github.com/jacopotarantino/WordPress-Cross-Domain-Plugin (via https://stackoverflow.com/questions/17491185/access-control-allow-origin-error-when-getting-wordpress-posts-in-phonegap-app)
Thanks. I gave that plugin a try. Didnât work for me.
This one is proving to be a hard nut to crack!
For anyone who runs into a similar issue, I finally found the problem. I had a php.ini file for the site that contained settings that were incompatible with PHP 7.3, which caused cPanel to fail to upgrade the site from PHP 7.2. This prevented the various header settings I tried from taking effect. Rebuilding the php.ini file from scratch resolved the issue.