Trying to change Content-Type: application/rss+xml
to Content-Type: something/else
on example.com/feed/.
My code so far:
function force_404() {
global $wp_query;
// Modify content-type header here, nothing I've tried works
status_header(404);
nocache_headers();
include(get_query_template('404'));
die();
}
add_action('do_feed', 'force_404', 1);
add_action('do_feed_rdf', 'force_404', 1);
add_action('do_feed_rss', 'force_404', 1);
add_action('do_feed_rss2', 'force_404', 1);
add_action('do_feed_atom', 'force_404', 1);
I initially thought the problem was the headers were already sent, but the 404 works, so that tells me they're still modifiable here. I'm at the end of my rope. Any help is appreciated.
Edit
My goal is to make the /feed/ 404 page render actual text/html in the browser instead of application/rss+xml, which renders as plain text. Changing the content-type
header to text/html
should do the trick.
Edit 2
It may not be possible to do this on /feed/
, here is my evidence. I'm going to hold out hope that someone can confirm or deny.
content-type: text/html
instead ofcontent-type: application/rss+xml
. This will make the page render actual HTML instead of printing the HTML code./feed
? A WordPress 404 page? Why? Are you doing this just for/feed
orfeed/<anything>
like/feed/atom
? How would people subscribe to your site's feeds, because your code is essentially disabling feeds, except that you're disabling it by serving a 404 page? 🤔