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 want to completely remove feeds from WordPress. I am using this little function from http://wpengineer.com/287/disable-wordpress-feed/

/**
* disable feed
*/
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);

Still there is tons of transient options.. like _transient_feed_mod or _transient_timeout_feed_mod

How can i completely remove feeds from WordPress?

share|improve this question
    
and tons of rewrite for feeds too.. those are in everywhere! –  Ünsal Korkmaz Nov 7 '11 at 9:44
    
curiously if you dont mind me asking ... why do you want to remove feeds from wordpress? –  Nicole Nov 7 '11 at 14:15
    
why should i need feeds in WordPress if i am not using it for blogging? –  Ünsal Korkmaz Nov 7 '11 at 17:13

4 Answers 4

up vote 6 down vote accepted

First step: remove the feed links from the section of your site.

<?php
add_action( 'wp_head', 'wpse33072_wp_head', 1 );
/**
 * Remove feed links from wp_head
 */
function wpse33072_wp_head()
{
    remove_action( 'wp_head', 'feed_links', 2 );
    remove_action( 'wp_head', 'feed_links_extra', 3 );
}

Next up, let's remove the feed endpoints from WP. Hook into init, globalize $wp_rewrite then set the feeds to an empty array. This effectively stops WordPress from adding feed rewrites. It's also super hackish and will probably break at some point in the future.

<?php
add_action( 'init', 'wpse33072_kill_feed_endpoint', 99 );
/**
 * Remove the `feed` endpoint
 */
function wpse33072_kill_feed_endpoint()
{
    // This is extremely brittle.
    // $wp_rewrite->feeds is public right now, but later versions of WP
    // might change that
    global $wp_rewrite;
    $wp_rewrite->feeds = array();
}

But, if it breaks, that's okay, because we'll redirect feeds to the home page.

<?php
foreach( array( 'rdf', 'rss', 'rss2', 'atom' ) as $feed )
{
    add_action( 'do_feed_' . $feed, 'wpse33072_remove_feeds', 1 );
}
unset( $feed );
/**
 * prefect actions from firing on feeds when the `do_feed` function is 
 * called
 */
function wpse33072_remove_feeds()
{
    // redirect the feeds! don't just kill them
    wp_redirect( home_url(), 302 );
    exit();
}

And the last step: an activation hook to set our rewrite feeds to an empty array and flush the rewrite rules.

<?php
register_activation_hook( __FILE__, 'wpse33072_activation' );
/**
 * Activation hook
 */
function wpse33072_activation()
{
    wpse33072_kill_feed_endpoint();
    flush_rewrite_rules();
}

All that as a plugin.

share|improve this answer
    
Sorry for late reply. Thanks for your time. –  Ünsal Korkmaz Jul 15 '12 at 15:19
    
Handy stuff. Thanks! I added a few feeds to your array. I know there are these two for comments: 'do_feed_rss2_comments', 'do_feed_atom_comments'. I believe that you also need 'do_feed'. I updated like this: add_action( 'do_feed' . ($feed ? '_' . $feed : ''), 'wpse33072_remove_feeds', 1 ); and the array: array('', 'rdf', 'rss', 'rss2', 'atom', 'rss2_comments', 'atom_comments'). –  Jake Aug 28 '13 at 2:37

This should do it

/*disable rss*/
remove_action('wp_head', 'feed_links', 2 );
add_filter('post_comments_feed_link','bfr_disable_comments_feeds');
function bfr_disable_comments_feeds() {
    return null;
}

Better yet, if you have at least PHP 5.3 you can use a shorter version:

/*disable rss, PHP 5.3+ */
remove_action('wp_head', 'feed_links', 2 );
add_filter('post_comments_feed_link',function () { return null;});

Removing rewrites, on the other hand, would take a lot longer, so unless you're totally nuts about performance you can leave them there.

share|improve this answer
    
Even shorter in more recent versions of wordpress: add_filter('post_comments_feed_link', '__return_false'); but this only hides a single link to comments feed. It misses... a lot to put it mildly... –  Jake Aug 28 '13 at 2:30

The code you posted will do exactly what it says it will - prevent anyone from accessing your site via an RSS feed.

Still there is tons of transient options.. like _transient_feed_mod or _transient_timeout_feed_mod

These transient options have absolutely nothing to do with your site feed. The WordPress dashboard consumes several feeds by default and displays them in boxes on the admin dashboard. Plugins you install might add their own feeds, either for news displays or for updates.

These transient values are used by WordPress to determine when these consumed feeds have been updated.

How can i completely remove feeds from WordPress?

The code you've posted already has ...

share|improve this answer

Full Solution to Clean & Disable auto-draft

========================================================

I use this code in function.php, which :
1) disables wordpress autosave and revision.
2) checks once in a day, and if it founds any auto-draft or revisions, it cleans the database .. (i havent directly disabled auto-draft, and its not a problem for me, as every day they are cleaned with this function)

if (is_admin()
    {
    //disable AUTOSAVE
    define('WP_POST_REVISIONS', false);
    //disable REVISIONS
    add_action( 'wp_print_scripts', 'disable_autosave' );
    function disable_autosave() { wp_deregister_script('autosave'); }

    //delete 'auto-draft'.. start this checker only on post publish/update  
    if (!empty($_POST['post_author'])) {
        if (!file_exists($temp_file) || file_get_contents($temp_file) < time() - 86400)
            {global  $wpdb; $temp_file='my_last_time_checker_';

            $del= $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'");
            $del= $wpdb->query("DELETE FROM $wpdb->posts WHERE post_type = 'revision'");
            $del= $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_rss%'");
            $del= $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_rss_%'");
            $del= $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_feed_%'");
            $del= $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_feed_%'");
            //if you want, you can uncomment these too
            //$del= $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_dash_%'");
            //$del= $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_dash_%'");

            file_put_contents($temp_file,time());   
            }
        }
    }
share|improve this answer
    
Please add some explanation. –  ialocin Nov 28 '13 at 23:21

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.