admin管理员组文章数量:1326512
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
2 Answers
Reset to default 1I'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
版权声明:本文标题:404 error - How to disable a Custom Post Type Feed? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742200801a2431923.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论