How to disable a Custom Post Type Feed?

I have been experiencing 404 errors in my Google webmaster tools reports, caused by Custom Post Type (CPT) feed URLs.

I would like to completely deactivate the CPT feed URLs, so that the 404 errors don’t appear anymore in my Google webmaster tools reports. In other words, I’d like to fix all these errors at once by deactivating the functionality that causes them.

2 Answers
2

I’m also getting an error similar to that. The feed links get generated and put into the and that is where your 404 error is coming from.

Here’s some code to disable feeds for a custom post type. https://gist.github.com/jaredatch/8610187#file-gistfile1-php

<?php
/**
 * Disable the "foo" custom post type feed
 *
 * @since 1.0.0
 * @param object $query
 */
function ja_disable_cpt_feed( $query ) {
    if ( $query->is_feed() && in_array( 'foo', (array) $query->get( 'post_type' ) ) ) {
        die( 'Feed disabled' );
    }
}
add_action( 'pre_get_posts', 'ja_disable_cpt_feed' );

Leave a Comment