Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Add a Custom Database Error Page in WordPress

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
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.

<?php // custom WordPress database error page

  header('HTTP/1.1 503 Service Temporarily Unavailable');
  header('Status: 503 Service Temporarily Unavailable');
  header('Retry-After: 600'); // 1 hour = 3600 seconds

  // If you wish to email yourself upon an error
  // mail("", "Database Error", "There is a problem with the database!", "From: Db Error Watching");


<title>Database Error</title>
body { padding: 20px; background: red; color: white; font-size: 60px; }
  You got problems.

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.

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. Arlen Nagata says:

    Now, is there an action to put this in your theme folder?

  2. David says:

    You know, I never thought about customizing that page. It’s a good idea because if a visitor comes across it at least it’ll fit the theme of your site and while they can’t see any info, maybe they can be amused.

    The email seems like a good idea because it could help gauge how often visitors might hit that error. If it happens a lot then Houston we have a problem.

    My only question goes back to the email. If a user lands on that page, I get an email. Will I get another email if that user reloads the page? Say the visitor lands, reloads in 10 seconds and continues. I don’t want to be spanned. Also, is the email hidden in the source code?

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.