admin管理员组

文章数量:1326683

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.

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.

Share Improve this question edited Aug 10, 2020 at 6:02 Dvaeer 6297 silver badges14 bronze badges asked Apr 22, 2015 at 13:26 dmtnexerdmtnexer 1411 gold badge3 silver badges11 bronze badges 2
  • If the URL is not valid and it doesn't exist in your webiste, 404 is the correct status and you should ignore the error in GWT. – cybmeta Commented Apr 22, 2015 at 13:40
  • but, why does the post contain this link to a not working URL? no other website does this to me and I do use CTP. – dmtnexer Commented Apr 23, 2015 at 13:04
Add a comment  | 

2 Answers 2

Reset to default 1

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/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' );

After some digging, we have noticed that a CPT must enable archives

'has_archive' => true

Must be set for the feed to function - otherwise you get a 404 error

本文标签: 404 errorHow to disable a Custom Post Type Feed