WP Development

I logged in to Google Webmaster Tools today and was greeted with a new crawl error, specifically a 404 Not Found for the Comments Feed url https://www.skyverge.com/comments/feed/. I requested the page and sure enough, it was indeed a 404.

A quick search turned up a number of threads and discussions regarding this issue, which seems to stem from having a new site without a single comment yet. How embarrassing. Now, let me stop you right there before you start blaming plugins and permalinks; as an experiment I installed a fresh Wordpress 3.3, did not install any plugins, left all defaults, deleted the default comment from Mr. Wordpress, and sure enough http://127.0.0.1/?feed=comments-rss2 returned a 404.

The Easiest Solution

Just chill and don’t worry about. Seriously, it’s a 404 on a single RSS feed that will resolve itself the next time someone leaves a comment; it’s not worth spending time searching through Google, and then a whole morning digging through WordPress core code…

The Easy Solution

Simply leave a comment yourself. But that just isn’t very cool, is it? Getting a friend to leave a comment would be slightly better, but still not as satisfying as knowing what the real issue is.

Under the Hood

If you’ve read this far, then like me you probably spend more time than you should on trivial things. I mean, you have drive and a thirst for knowledge, sweet! This rogue 404 seems to boil down to the handle_404() method of the WP class, unsurprisingly I suppose. Being fully aware that modifying core files is a cardinal sin which I never commit, and that the next WordPress update will remove this fix, making the following change doesn’t concern me overmuch since it’s targeted at a temporary issue that will resolve itself naturally with time. Disclaimer: I don’t consider myself an expert in the WordPress core yet, so I can’t be sure that making this change won’t have dire consequences for a site. If you’re foolish enough to try this and your blog catches fire and falls from the sky, don’t blame me! And with that out of the way, my solution is to add a !is_feed() check to the handle 404 method to exclude feed pages from the 404 check, as shown in the complete and modified method below:

function handle_404() {
  global $wp_query;

  if ( ! is_admin() && ( 0 == count( $wp_query->posts ) )

       && ! is_404() && ! is_robots() && ! is_search() && ! is_home() && ! is_feed() ) {

    // Don't 404 for these queries if they matched an object.
    if ( ( is_tag() || is_category() || is_tax() || is_author() || is_post_type_archive() ) && $wp_query->get_queried_object() && ! is_paged() ) {

      if ( ! is_404() ) {
        status_header( 200 );
      }

      return;
    }

    $wp_query->set_404();
    status_header( 404 );
    nocache_headers();

  } elseif ( ! is_404() ) {

    status_header( 200 );
  }
}

File: wp-include/class-wp.php

This will exclude all feeds from the 404 check and resolves the 404 Page Not found for my Comments Feed: https://www.skyverge.com/comments/feed/. Hooray!

Published by Justin Stern

Justin is one of our co-founders, and is our resident overengineer. He likes to write developer tutorials and make black magic happen in our plugins. He thinks that writing code is a lot easier than writing words.

22 Comments

  1. Avatar

    There might be the possibility that a website running WordPress is not blog or a site with comments as a needed functionality.

    However I don’t know how Google reaches /comments/feed/ if there is no reference in the site.

    The last hack you gave is perfect for the situation I said earlier.

    Thanks!

  2. Avatar

    Thanks for the post.

    I made a slightly modified change to the class-wp.php file.
    if ( is_admin() || is_robots() || $wp_query->posts || is_feed())
    to
    if ( is_admin() || is_robots() || $wp_query->posts || is_feed() )

    I was hoping a WP update would fix it but when it didn’t your hack put me in the right direction.

  3. Avatar

    What do you suggest if i’m not allowing comments on my site, and hence it won’t fix itself when someone leaves a comment?

    • Avatar

      Hmm, that is an interesting question. Well, you can certainly implement my fix, you’ll just have remember to do it each time you upgrade WordPress, which at least doesn’t seem to happen all that often. On the other hand it really isn’t that big of an issue, it just annoyed me seeing that 404 reported in Webmaster Tools.

  4. Avatar

    Hello Justin, I came up with another solution which was introduced here:

    http://www.blogofchris.com/remove-comments-rss-feed-wordpress/

    It’s more of a brutal way, if you just delete some lines of code, but i may work for some people, as it had for me πŸ™‚

    Took me some time to find these lines of code in the source of WP and maybe it will change in the future again. It would be nice, if we had an WP option to enable / disable feed comments..

    • Avatar

      Yeah, I didn’t want to totally remove the comments RSS feed, just to fix the 404 when there were no approved comments. For someone looking to completely do away with that feed, that’s certainly one way to go. Thanks for sharing!

  5. Avatar

    hahahaha thanks justin. You saved my time.

  6. Avatar

    A much cleaner way would be to add this to your functions.php

    add_action(‘init’, ‘remove_feed_links’);

    function remove_feed_links() {
    remove_action(‘wp_head’, ‘feed_links’, 2);
    remove_action(‘wp_head’, ‘feed_links_extra’, 3);
    }

    This stops WordPress from generating the links that search engines would follow. But there is a caveat. The main site RSS link is also removed. For fixing it just drop this into your header.php before closing tag.

    <link rel="alternate" type="application/rss+xml" title=" RSS Feed” href=”<?php bloginfo( ‘rss2_url’ ); ?>” />

    No messing around with WordPress core. πŸ™‚

  7. Avatar

    thanks!

    got it fixed~~

  8. Avatar

    Legend… This is the only post I have found that has helped me resolve this problem, brand new blog therefore no comments, just knowing that and that is will go away once a comment is all I need to know. Fantastic stuff, many thanks πŸ™‚

  9. Avatar

    Lol, for me the most relevant sentence of this article turned out not to be the knowledge that all new sites without a single comment have this issue but that, like you, “I probably spend more time than [I] should on trivial things”. Doh! I wonder if there is an app / life hack for that or if I need brain surgery?

  10. Avatar

    Thanks so much for this!

    Not good when you see 400 404 errors cropping up!

    Thanks Again!

  11. Avatar

    I had the same problem as you, Your solution was a perfect fix for this problem. and I no longer have the error message coming up. Thank you and have a nice day.

  12. Avatar

    I’ve also spotted this error in my Webmaster Tools account and am grateful for all the help on this page. I’m no developer by any stretch of the imagination so I’ve gone with the 2 updates which Justin Vinny had added in the comments. Fingers crossed but otherwise, no sweat! Many thanks.

  13. Avatar

    Pretty! This was a really wonderful article.
    Thanks for supplying this info.

  14. Avatar

    Great job, but for me you do not need to code to resolve the 404 error with comments/feed. Simply comment a post and you will never have a 404 on your comments feed.

Hmm, looks like this article is quite old! Its content may be outdated, so comments are now closed.