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(“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>

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!

Pin It on Pinterest

Add address