Skip links
Custom Database Error

How to Add a Custom Database Error Page in WordPress

Have you seen your WordPress website’s ‘Error establishing a custom database connection’ error page? This message can be displayed for various reasons, but it needs to be more appealing and may cause confusion among visitors.

Also, you will know your website is down if you visit it and see the message. This post will show you how to personalize your WordPress database error page. We’ll also teach you how to set up notifications for when your website goes down due to a custom database fault.

What Reasons for the Custom Error Database Connection?

“Error establishing a database connection” is one of the most common WordPress errors. It may be caused by inaccurate database information in your WordPress settings, a faulty database, or an inaccessible custom database server error.

Solving this mistake can be difficult for beginners, so we’ve included a variety of alternatives in our article on how to fix the ‘mistake of establishing a custom database connection’ in WordPress.

The last thing you want your visitors to see is a generic error message from WordPress. The error page is vague, unappealing, and lacks your trademark. It looks like your website disappeared.

With that said, let’s take a look at how to make your WordPress website’s error page more helpful.

Adding a Custom Database Error Page in WordPress

First, open a new file in a text editor like Notepad and paste the following content inside.

<?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("your@email.com", "Database Error", "There is a problem with the database!", "From: Db Error Watching");
   
?>
   
<!DOCTYPE HTML>
<html>
<head>
<title>Database Error</title>
<style>
body { padding: 20px; background: red; color: white; font-size: 60px; }
</style>
</head>
<body>
  You got problems.
</body>
</html>

Next, name the file ‘db-error.php’. Next, use an FTP tool to upload the file to your WordPress site’s /wp-content/ directory. For additional information, see our beginner’s guide to using FTP with WordPress.

When your website is unable to create a custom database connection, you will notice the error message in the screenshot below, as well as the title “Custom Database Error” in the web browser’s tab.

It’s not the most attractive-looking error message, but it’s a step forward. You can now customize the page’s HTML and CSS to better fit your website.

Custom Database Error Page in WordPress

Now it’s time to make your custom database error page look beautiful and complement the rest of your website’s layout. You should also include your brand logo and tagline on the page.

You might also include some humour in your message. Your guests may be able to browse your website, but you can still keep them entertained.

You can get inspiration from our selection of the greatest WordPress 404 error page design examples. For example, the Empty Cup 404 page might be readily repurposed as a custom database error page.

You would have to update ‘Error 404’ to ‘Custom Database Error’ and ‘This page cannot be found’ to ‘This website is temporarily unavailable’. You should also remove the ‘Go Home’ option, as your entire website is most likely offline.

The SeedProd plugin provides the simplest method for designing a custom database error page. It is the most popular landing page builder, featuring drag and drop capability that allows you to customize your error pages without modifying any code.

It includes over 300 professionally designed templates, including multiple 404 error page templates that you can use to create your own customized database error page.

SeedProd has a free version, however the built-in 404 error page templates are only available in the Pro edition.

For ideas on how to use SeedProd to generate custom error pages, see our guide to improving your WordPress 404 page template.

Sending an Email Notification for the Database Error

If your website is down, you should be notified so that you can take the necessary steps.

The code snippet we used before includes code to send you an email notification if your website has a database error. That section of the code is now inactive because it is commented out with two slashes.

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

To receive notifications, delete the two slashes before the mail function.

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

You’ll also need to change ‘your@email.com’ with your actual email address. Don’t forget to save and upload the updated db-error.php file to your WordPress site’s /wp-content directory.

Also, Read More Relevant Articles

The Final Thought

In conclusion, creating a custom database error page in WordPress is a practical way to improve the user experience while maintaining professionalism on your website. By following the methods indicated above, you can effectively develop a custom error page that is consistent with your site’s looks and branding while also offering relevant information to users experiencing database difficulties.

Remember to extensively test your custom page to verify it works properly and provides useful information to your visitors in the event of a database disruption. This feature allows you to reduce frustration while maintaining a great user experience, ultimately adding to the success of your WordPress site.

Leave a comment

This website uses cookies to improve your web experience.
Home
Account
Cart
Search
Explore
Drag