Here’s how to make a custom database error page for WordPress.
If your site’s all set up and you see “Error establishing a database connection,” that’s an immediate “oh crap” situation.
Hostgator.com, the company that hosts this website, has had some issues recently, and I’ve seen that screen a little too often.
If you want to define a custom “Error establishing a database connection” screen, add a file to your
/wp-content/ folder named
db-error.php. That will be loaded instead of that stupid message. Check out SEODenver.com’s
A Good Idea for SEO
If you want to prevent search engines from indexing your site while it’s down, add
<meta name="robots" content="noindex, nofollow" /> to your page’s
<head>. You sure don’t want Google caching your error!
Once you do that, you’re going to also want to tell search engines you’re having issues. For that, send them an error 503 by adding the following to the top of your PHP file:
<?php header('HTTP/1.1 503 Service Temporarily Unavailable'); header('Status: 503 Service Temporarily Unavailable'); header('Retry-After: 7200'); // in seconds ?>
Get the code for my db-error.php
If you’d like a head start (a very simple head start), grab the plain text of my error page.