WordPress 2.3+ official support for custom database error page

  • February 11th, 2008

Some time ago a tutorial was posted on 5ThirtyOne which addressed customizing the DB Error page rendered whenever visitors landed on heavily trafficked WordPress site. Since then, the method has been proven "useless", ushered away by recent updates to the WordPress code base; more specifically with the release of WordPress 2.3.2 (current release is 2.3.3). Whereas the previous method required manipulating code within a core WordPress file, the new updated method allows for the custom page to be stored externally of the WP root directory. To get started creating your own custom WordPress database error page, follow the two steps below:

Create a db-error.php file in /wp-content/

First things first. Create an XHTML file called db-error.php and upload it to the WordPress /wp-content/ directory.

DB Error file in Transmit

Because visitors will see this page when your WordPress driven website is experiencing database connection errors, you will need to make sure the file includes any style attributes inline, or reference an external stylesheet (absolute URL).

<style type="text/css">...your CSS goes here...</style>

or

<link href="http://url.com/my-stylesheet.css" rel="stylesheet" type="text/css">

For the sake of simplicity, we’ll create a custom database error page with a single XHTML document including any style attributes inside the <head> tags. The following is the message skeleton originally created and used in the tutorial here.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<title>My server crashed, please call the next of kin</title>
<style type="text/css">
body {
font-family: arial, verdana, sans-serif;
font-size: 62.5%;
background: #fff;
color: #333;
text-align: center;
}
a {
text-decoration: none;
outline: none;
}
#error_wrapper {
font-size: 1.3em;
margin: 5em auto 0;
text-align: left;
width: 333px;
}
.content_wrapper {
padding: 1em 0.7em 0;
}
</style>
</head>
<body>
<div id="error_wrapper">
<div class="content_wrapper">
<p>It looks as though my server has taken an unsupervised leave of absence. I may not know of its whereabouts so would you be so kind as to notify me via <a href="mailto:admin@domain.com" title="Send me an email">email</a>?</p>
</div>
</div>
</body>
</html>

Second step, there is none

If you created a standard XHTML document and dropped the code in db-error.php inside the /wp-content directory, there really isn’t anything else to do other than to ensure that your site visitors never see a WordPress database error page while visiting your site.