Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.