WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a theme I'm building, I have this structure for detecting what type of page something is. However, if I visit mydomain.com/category/ or mydomain.com/tag/, all I get is the "nothing found" message I have in the have_posts()'s else statement. Is there a way to detect when these links are visited and display something other than what's in the final else statement?

   echo '<h1>title here</h1>';
   echo '<h1>title here</h1>';
   echo '<h1>title here</h1>';
   echo '<h1>title here</h1>';

     //the loop
    echo '<h1>Nothing Found</h1>';
share|improve this question

There is no good way to do this, but it can be done in a way. When you visit /category/ it serves it as though you are visiting a page called category. You can look for this like:

global $wp_query;
if ($wp_query->query_vars['pagename'] == "category")
  // This is base category
else if ($wp_query->query_vars['pagename'] == "tag")
// this is tag base

But this should never be done. It is basically a junk query; a 404, and will send a 404 response code, so you will need to look at sending another response code. For that reason (if you decide to use it) this code should go in header.php although it could go high in 404.php (before any output).

share|improve this answer
When the example code I posted is used, there is no actual 404 error generated. Would it be better to redirect those pages to the home page instead, and how would that be done? – Force Flow May 29 '12 at 1:35
up vote 0 down vote accepted

If I put this above the htaccess block of wordpress rules, I'm able to redirect the tag and category base pages back to the homepage.

RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^category/?$ "http://mydomain.com" [R=301,L]
RewriteRule ^tag/?$ "http://mydomain.com" [R=301,L]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.