How to Add a Custom Database Error Page in WordPress

You ever remember seeing a screen like Error Establishing a Database Connection on your site. This can happen for various reasons, but often users don’t know that their site is down. Also that page itself looks pretty ugly in itself. In this article, we will show you how to customize your database error page in WordPress. We will also show you how to setup a notification for every time your website goes down due to a database error.

Open a new file and save it as “db-error.php”. Paste the following content inside that. Then upload the file in your /wp-content/ directory.

01 <?php // custom WordPress database error page
03   header('HTTP/1.1 503 Service Temporarily Unavailable');
04   header('Status: 503 Service Temporarily Unavailable');
05   header('Retry-After: 600'); // 1 hour = 3600 seconds
07   // If you wish to email yourself upon an error
08   // mail("your@email.com", "Database Error", "There is a problem with the database!", "From: Db Error Watching");
10 ?>
13 <html>
14 <head>
15 <title>Database Error</title>
16 <style>
17 body { padding: 20px; background: red; color: white; font-size: 60px; }
18 </style>
19 </head>
20 <body>
21   You got problems.
22 </body>
23 </html>

Source: CSS Tricks

If you want email notifications, then comment out the mail line. To comment it out, you have to remove // before the mail function. Feel free to customize the landing page however you like. Use these 404 design inspirations as a start.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s