I am trying to add CORS (http://enable-cors.org/) support to an RSS2 feed within a custom WordPress theme. I have tried the following, all to no avail:
-
Following the instructions on https://web.archive.org/web/20140314152828/http://bowdenweb.com:80/wp/2011/05/how-to-enable-cors-in-wordpress.html, I attempted to modify the theme’s header.php file and add the following code to it:
header("Access-Control-Allow-Origin: *");
This was successful in adding the CORS header to the WordPress posts, but not to the RSS2 feed.
-
Then, I attempted to use the “Plugin API / Action Reference”, i.e. the
add_action
function (http://codex.wordpress.org/Plugin_API/Action_Reference).I added the following code to header.php:
function add_cors_headers() { header("Access-Control-Allow-Origin: *"); } add_action('rss2_head','add_cors_headers');
Again, no success. Now I am at a dead end. Any ideas?
You could do it like this with a plugin or by adding to functions. I think that ends up being cleaner.
Copy the original rss-template “wp-includes/feed-rss2.php” to your theme directory and activate it by adding this code to your functions.php:
Then you can modify your rss-template and add the header like mentioned by jefffederman.
Go to wp-includes/feed-rss2.php and below
add