WordPress Comments Feed 404 Fixed February 03 2012

Wordpress 404

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 http://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: http://www.skyverge.com/comments/feed/. Hooray!

The post WordPress Comments Feed 404 Fixed appeared first on SkyVerge.