WordPress Hack – Category And Authors Without Posts

WordPress, by default, redirects you to the error page when you try to visit a category or an author without posts. This is acceptable in a lot of cases. However, in some cases, you might want to display them anyhow. Maybe you can show just the author profile with a message that the author has not authored any posts yet. I have not been able to find a non-hack solution to this yet, so here is the hack.

The 404 or the error page is issued by the method handle_404() of class WP in wp-includes/classes.php file. If certain conditions are met, it does not redirect. All we need to do is add our conditions to that. We can do this by adding !is_category() for category and !is_author for author. So the entire if statement looks like:

Now your template files for category and author will be executed even if they do not have any posts.

This is a hack, which I am not very fond of. I have used it in the Complete Wellbeing web site to handle profiles of multiple authors. But I will be looking for a better solution. I wonder if the redirection to the error page can be given to the individual templates. Also if more hooks can be added into WordPress so that certain parts of the template hierarchy are modifiable through plugins.