How to add CORS support to Wordpress RSS2 feed?
You could do it like this with a plugin or by adding to functions. I think that ends up being cleaner.
add_action( 'pre_get_posts', 'add_header_origin' );function add_header_origin() { if (is_feed()){ header( 'Access-Control-Allow-Origin: *' ); }}
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:
remove_all_actions( 'do_feed_rss2' );add_action( 'do_feed_rss2', 'my_feed_rss2', 10, 1 );function my_feed_rss2( $for_comments ) { $rss_template = get_stylesheet_directory() . '/feed-rss2.php'; if( file_exists( $rss_template ) ) load_template( $rss_template ); else do_feed_rss2( $for_comments ); // Call default function}
Then you can modify your rss-template and add the header like mentioned by jefffederman.
Go to wp-includes/feed-rss2.php and below
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
add
header("Access-Control-Allow-Origin: *");