Disable feeds for specific custom post types

I want to remove the feeds for specific custom post types. Most recommended methods are not clean. There seems to be a option called $args->feeds but this does not work within the register_post_type() function.

 register_post_type(
  ...
   'rewrite' => array('slug' => 'slug/%term&', 
                      'with_front' => false,
                      'feeds' => false), // Remove feed rewrite-rules?
  ...
 );

Source: Line 1324 – /wp-includes/post.php (WordPress 3.5)

Read More

I’m looking for a solution, to disable the rule generation inside $wp_rewrite->rules.

Related posts

Leave a Reply

1 comment

  1. Taking a look at the register_post_type() function in WordPress source, it appears that WordPress uses isset() to check the feeds arg instead of empty(), meaning that a false value will return true. To fix this, you might try setting 'feeds' => null and then flush your rewrite rules from Settings > Permalinks (remember to do it TWICE, to get past a weird quirk).

    Alternatively, you can shut down any other page (including feeds) before it has a chance to load…

    do_action('wp','kill_feeds',-1);
    function kill_feeds(){
        if ( is_feed( array('post','my-custom-type') ) ) {
            exit;
        }
    }
    

    What this should do is detect if the current request is a feed (of the specific post types you specify) and, if it is, stops any further output.

    If you wanted to get really crazy, you could redirect to your sites 404 page instead. 🙂

    Finally, failing all that, you could modify your rewrite rules manually. The rewrite_rules_array filter exposes the entire rewrite rules array and you can work a little regex magic to remove any applicable feed rules. Assuming your post was ‘foo’, this might look like…

    add_filter('rewrite_rules_array', 'kill_feed_rewrites');
    function kill_feed_rewrites($rules){
        foreach ($rules as $rule => $rewrite) {
            if ( preg_match('/^foo.*(feed)/',$rule) ) {
                unset($rules[$rule]);
            }
        }
        return $rules;
    }
    

    Feed reference, the rules themselves look something like this…

    'foo/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]'