Add Access-Control-Allow-Origin: * to feed?

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.

1 Like