Search code examples
feedwordpress

I need to block my feed completly


I'm in need a solution via coding. on how to completely hide my blog feed. I know how to optimize related hook and filter such as 'the_excerpt_rss' and 'the_post_rss'. And also understand how to limit access or make my blog private.

So, the question is more about how to blocking feed access without make my blog private ?

I hope the solution will be not some apache .htacceess. Cause I need to code it directly into my theme..


Solution

  • This should do it in functions.php without having to edit core WP files:

    function fb_disable_feed() {
        wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') );
    }
    
    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);
    

    Also remove the feed link in your header.php