Your plugin file should consist of exactly this code:
<?php
/**
* Plugin Name: T5 404 Feed
* Description: Sends a 404 status code for all feeds and loads the <code>404.php</code> template.
*/
add_action( 'template_redirect', 't5_404_feed', 1 );
function t5_404_feed()
{
if ( is_feed() )
{
status_header( '404' );
header('Content-Type: text/html', true);
locate_template( array ( '404.php', 'index.php' ), TRUE, TRUE );
exit;
}
}
Without the header()
function, the page is being delivered as an RSS feed (content type of application/rss+xml
) and you need it delivered as HTML (content type of text/html
).
If you are getting errors when installing / activating, then something else may be interfering. I tried this code as a theme modification and it works fine. I have not tried it as a plugin. Often, there is a php_error.log file somewhere on your server where you can see the exact error that’s occurring. If you find it, please post it here.
HTH