How to Add a Custom Database Error Page in WordPress

How to Add Custom Database Error Page in WordPress and why is explained in this article.

After syntax and 404 error, database connection error is the most frequent error you are likely to see on your WordPress site.

There are various reasons for its occurrence and unlike 404 error, you may not know about the web pages showing database connection error unless someone reports you.

As a matter of fact, database connection error can make your entire website down.

The user will down the error page which looks quite ugly and if they happen to see very often, they are likely to stop visiting your website and unsubscribe you.

In such a scenario, it is important to add a custom database error page in WordPress.

It is also important from your side to get a notification every time your website gets down with database connection error so that you can approach your technical team or web host to fix the issue immediately and for the time being, you can run your website from another backup server if you have one.

One of the common reasons for database connectivity error is when you migrate your website from one web server to another.

WordPress interact with MySQL database through the scripting files and once the connection is established and data are fetched, the webpage appears for the users.

custom database error page

If there is any problem, your user will see “Error Establishing a database connection” and the script from the file.

error establishing database connection

Why Should You Add A Custom Database Error Page In WordPress?

There is always a big chance that the script displayed due to database connectivity error could help the attackers to find loopholes.

It is generally not the case but there is a possibility. Therefore, you should never risk it and show a custom database error page where no script or details are displayed.

Furthermore, your normal users will be completely pissed to see an ugly database error page shown by WordPress.

He can unsubscribe your newsletter, notifications and unbookmark you.

Why piss them off when you can show something else to keep them engaged and promise them to comeback soon.

Moreover, every time your custom database error page is used in WordPress, you will be notified and you can take actions immediately. In this article, we will show you how to add a custom database error page in WordPress.

Steps To Add A Custom Database Error Page In WordPress –

If you are wondering how it works, you should know that it works automatically.

In other words, whenever WordPress fails to connect to the database, your custom database page will be displayed automatically.

If your custom database error page is not available, it will show the default ugly one.

Step 1. You have to create a file and name it db-error.php. You have to paste the following code in it.

<title>Database Error</title>

body { padding: 20px; background: red; color: white; font-size: 60px; }

  You got problems.

If you want notification to your email every time this file gets executed on your server which in other words mean that you have database connectivity error on your website, you need to remove the comment symbol about the mail function written above.

custom database error message

Step 2. You have to connect your FTP to your web server and inside wp-content, you have to place the file. That is it and you can customize your custom database error page as per your liking to make it interesting and creative.

Here is another example of lines of code that you can be used instead of the above-mentioned one.

        <title>503 Service Temporarily Unavailable</title>
            h1, p {
                font-family: Helvetica, sans-serif;
                font-size: 24px;
                color: #333;
            p {
                font-size: 14px;
        <h1>Captain, the ship can&rsquo;t take much more of this!</h1>
        <p>Hard workers are currently working on the issue &mdash; Please check back soon!</p>

This is how you can show funny messages so that the users do not get users and eliminate you. If you know CSS coding, you should make it more visually appealing so that it means something rather than just unappealing plain white background.

If you see the code, there are three different headers present. The first and second one is 503 server and status response which will ask the users to try back. But the third one Retry-After will show the users after how much time, they should try back.

Tips On How To Add A Custom Database Error Page In WordPress?

1. You should definitely add your brand logo and tagline to make it look good.

2. You can also add URLs of some of the best articles on your other website or some static pages you have on your website that are not dependent on database connectivity. You can also paste the link of your social media channels so that your loyal visitors that check them out to see the updates when it comes live.

3. You can cover up by not displaying it as a database error and say that it is down for some upgrades.

4. If the issue will take some time to resolve, you can forward an email to your subscribers regretting the fact and notifying them when it is likely to come back.

seedprod coming soon

Lastly, there are various custom database page templates available for free on the internet that are very amusing, interesting and attractive.

Download the best one from them and use the same of your site to amuse your visitors while your site is down due to database connectivity error.

If you have a thriving business and an online presence, then you already know that the website can malfunction from time to time for various reasons.

This happens to be the case with WordPress sites as well except that WordPress comes loaded with various tools including custom database error page in WordPress that allow you to instantly hone in on the issue and will even help list out the various measures that you can take, to resolve the same.

That’s why you may want to base your website on a WordPress platform and to that end, do check out some of our themes.

Getting back to the topic, customers are not going to be too happy to see a database error or even a blank page pop up once too often.

This is usually an indication that there is something inherently wrong with the theme, and the overall design and that you would have to contact WordPress support and usually, they are quite proactive and will get back to you right away on the same. What’s more, if you do not take immediate action your SERPS rankings are bound to get affected as well.

This is why it is vital that you have a custom database error page so that you can inform your customers regarding the issue and let them know when they can expect the content to be listed again.

Setting up a custom database error page in WordPress is not that difficult; you should be able to set it up in minutes. One of the reasons as to why you are facing this issue could be the fact that you had recently migrated to WordPress and that’s the reason why the error page is often coming up.

Here’s what you can do to set up a custom error page and even set it up in such a way that you get an instant notification each time your site is down. The good news is that you do not have to code for pages to set up the custom database error page up.

All you have to do is to head over to your website and upload a file named db-error.php to the root of your content folder and that should do the trick. You can also search online for detailed step by step directions but this is essentially the process by which you can set up a custom database error page.

Your customers would appreciate the effort that you had taken on their behalf. One tip, you may want to ensure that Google does not index your custom error page otherwise this could well turn out to be the page that customers are directed to. And if you know HTML and CSS you can always design this custom database error page as per your preference.

But even if you do not know coding, it should not matter much since you should have been able to set up the error page with ease.

About Sonnal S Sinha

Sonnal S SinhaSonnal S Sinha shares exciting WordPress themes, plugins and other WordPress related news for our viewers. He also posts selected WordPress developers interviews from time to time.