Home  »  ArticlesGuidesTips   »   How to Change the Database Error Page in WordPress

How to Change the Database Error Page in WordPress

WordPress is this great piece of software for creating great websites but like many great things, they also leave a lot to be desired when it comes to certain things and one of them is the database error page.

WordPress is an open-source web application software for developing websites, blogs, and web applications that have had a lot of work put in by the development team and community at large.

There are some aspects of the application that have not gotten as much attention for one reason or another. One of these is how the application handles database and other server errors.

WordPress handles this by putting out a simple one-line message is boring, or should we say ugly text printing out the issue. One may argue that the text message through informative can be a security risk depending on how you choose to look at it.

Database Error

Furthermore, it breaks the consistency in the look and feel of your website’s brand which obviously has a lot of thought and work and put into it. So how do we fix the problem? Well, it is quite simple to do as you will below.

Customizing the Database Error Page

The first thing is obviously you need to have access to the WordPress directories. Inside the /wp-content/ folder, you need to create or upload a file named “db-error.php“. Whenever WordPress has a database issue and finds that file, It will actually process that file accordingly.

In that file is where you can customize your HTML and CSS to match your website theme. You can also change the message to something that is more exciting than the default. The other things that would be nice to have in that file is some headers to let your browser know what is going on and probably retry the link and even send out an email to the website administrator to let them know something is a miss.

Below is a template that you can use to get started with your customizing the Database error page.

<?php // custom WordPress database error page
// Tell the browser that there is a bit of a mess on the server
  header('HTTP/1.1 503 Service Temporarily Unavailable');
  header('Status: 503 Service Temporarily Unavailable');
  header('Retry-After: 600'); // in seconds = 10 minutes

  // You can send yourself an email notification
  mail("[email protected]", "Database Connection Error", "Problem with the database! Come fix me!", "From: My Website's DB");
  // Put out the customized friendly template that matches your website

<title>Database Connection Error</title>
  Any required CSS rules here
  State what you going through in a public friendly way.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Available under:
Articles, Guides, Tips