I once owned a t-shirt portraying Jean-Paul Sartre’s answering machine; I’m fairly sure the source of the message is a pre-1997 internet meme, one of those emails that wents the rounds of everyone who actually had a computer back then.

“I’m not here… you’re not here… don’t leave a message… there is no beep.”

404 pages always seem a bit like that to me; despite the clamour of accessibility zealots, I prefer sites whose 404 pages retain a sense of mystery and playfulness, sites that are prepared to have a little fun with their readers. It’s possible to do this without sacrificing usability, although it’s not something I’d do on a commercial site (unless, of course, it catered to people as weird as myself). Currently I have a deeply tedious 404 message, but hopefully my brother will write me something amusing to put there (he’s a lot funnier than I am).

While we’re on the subject, I thought I’d explain the process of getting custom 404 pages running in WordPress. It seems fairly simple once you’ve set it up, but fiddling with .htaccess files can be confusing at the best of times, and there’s not much in the way of clear documentation (I found the answer I was looking for on the WordPress Support Forums after about ten minutes cursing at the WP Codex).

Firstly, create a custom 404 error page. It needs to be saved as 404.php and uploaded to your theme directory; more on this here. Here’s the code for my 404 page:

<?php get_header(); ?>
 
<div id="primary">
 
<h2>Error 404</h2>
 
<p>The page you are looking for does not exist; it may have been moved, or removed altogether. You might want to try the search function or check the <a href="http://ionfish.hwcommunity.com/archive/">archive</a>. Alternatively, return to the <a href="<?php echo get_settings('home'); ?>">front page</a>.</p>
 
</div>
 
<?php get_sidebar(); ?>
 
<?php get_footer(); ?>

All it does is get the header, display the error message, then get the sidebar and footer, creating a simple 404 error page. The next step is to add the following to your .htaccess file (this ought to be in the root of the directory where your blog is displayed).

ErrorDocument 404 /index.php?error=404

That gets WordPress to display your custom 404 error page whenever someone tries to access a page that isn’t there. Of course, you could make the 404 page more complicated (having the search function use their URL string as the initial search value is neat trick I’ve seen in various places, such as Binary Bonsai), and at some point I might, but for the moment I’m happy just to have it working.

As a side note, the code I posted above was helpfully massaged by the Preserve Code Formatting plugin, which was suggested here. It seems to work fairly well, although I might look into making it all look a bit better (possibly with the assistance of a PHP function like highlight_string() or another WordPress plugin—suggestions appreciated).