Returning 404 when a category is empty is unacceptable in SEO practice. I encountered this problem in WordPress 2.0.2.
By default, WordPress hides empty categories but there is an option to show them:
wp_list_cats(‘hide_empty=0’);
If I decide to show empty categories, WordPress should not be displaying 404 Not Found when users go to click on them.
Google and other search engines won’t index 404 pages, and if they were previously indexed they get dropped. Very bad!
Instead what we want is for WordPress to decide, “Is the category Not Found or is it really just empty?”
In the default WordPress theme by Michael Heilemann, the template file archive.php is prepared to work this way:
if (have_posts()) :
// begin the Loop to show posts
else :
// explain that there are no posts here
endif;
… but it never gets the chance. *sigh* So here is how you fix the problem.
inside /wp-includes/classes.php on line 1698:
if ( (0 == count($wp_query->posts)) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER[‘QUERY_STRING’]) && (false === strpos($_SERVER[‘REQUEST_URI’], ‘?’))) ) ) {
becomes:
if ( (0 == $wp_query->query_vars[‘cat’]) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER[‘QUERY_STRING’]) && (false === strpos($_SERVER[‘REQUEST_URI’], ‘?’))) ) ) {
Then modify your archives.php inside the /theme directory so it is like Heilemann’s example above, but instead of:
<h2 class=”center”>Not Found</h2>
<?php include (TEMPLATEPATH . ‘/searchform.php’); ?>
i recommend:
<h2>Empty</h2>
No posts here yet.
or even:
<h2>Stay tuned!</h2>
This is a new category. Watch for new posts to appear here soon.
NOTE: This is assuming you provide the search box in your sidebar like most people do; if that assumption is wrong, make sure you provide the include for searchform.php!
And that fixes that.