I would like to redirect my visitors to my 404 when they visit any feed of my page. Something like this. I would liek to do this without changing the header URL.

function fb_disable_feed() {

// set_404();

}
add_action('do_feed', 'fb_disable_feed', 1);
add_action('do_feed_rdf', 'fb_disable_feed', 1);
add_action('do_feed_rss', 'fb_disable_feed', 1);
add_action('do_feed_rss2', 'fb_disable_feed', 1);
add_action('do_feed_atom', 'fb_disable_feed', 1);

Please help!

1 Answer
1

There are three simple steps to get what you want:

  1. Hook into 'template_redirect' to act before the feed is displayed.
  2. If it is a feed send a 404 status header and
  3. load the 404 template.

Here is a simple plugin that does it:

<?php # -*- coding: utf-8 -*-
/**
 * 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' );
        locate_template( array ( '404.php', 'index.php ' ), TRUE, TRUE );
        exit;
    }
}

I am not so sure that 404 is the proper status code. 410 (Gone) may fit better.

Leave a Reply

Your email address will not be published. Required fields are marked *