Create a WordPress database error page
I guess that many of you already got this message on your WordPress installation “Error Establishing a Database Connection“. This is pretty commun and can be temporarily seen by your visitors. This message can appear when your wp-config.php isn’t properly configured, or when your database (or your hosting) is down. This page can have a negative impact both on your visitors and on your SEO. Let’s see how to create a custom database error page.
The first thing to know is that when there’s a database connection problem, WordPress itself will automatically display a message, but it’s ugly and non-professional. So to customize this message, all you have to do is to create a file called db-error.php inside your theme folder or under wp-content.
Tell Google it’s temporary
Once you created the db-error.php file the first step is to tell Google and other search engine that it’s just a matter of time before the website come back on line, it’s temporary.
Send an alert to the webmaster
Sometimes your website is down and you just don’t know it, so inside the db-error.php we are going to add a function that will send an email to the webmaster to tell him that the site is down, and that he probably has to check a few things (first thing to check: did i pay the hosting bill?).
Inform the visitor with a nice custom message
And then you have to display a message for your visitors to telle them the site is unavailable. Just create a simple html page with your logo, your colors, and a message to invite them to come back later. You can add links to your social pages such as Facebook, Twitter, Youtube or whatever. You can also invite them to subscribe to your newsletter etc… Just don’t forget that the more the visitor will think that you anticipated this kind of issue, the more he will be ready to come back on your site.
The db-error.php code
You can use and customize the code below: