Creating a Custom Database Error Page and Error Notification for WordPress

AD

We all know that custom 404 pages covert in better user experience, but what about database errors?

Sometimes, WordPress powered websites face a different kind of error, which is a database error. This error doesn’t only reduces user experience, it also puts load on the server that can lead to server crashing down.
So today, we are sharing a simple micro-tutorial for creating a custom database error page in WordPress.

I’ll be taking a little help from this snippet here. We’ll be adding the usual error message data, but you can fill in anything using simple HTML/CSS.

In addition to everything else, there is an email function included in this code which will send you email whenever there is any error in your database and this page is displayed.

Let’s begin:

All you have to do is create a file called “db-error.php” with the code below and put it directly inside your /wp-content/ folder and WordPress will automatically use that when there is a database connection problem.

Error Page PHP Part

<?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 Replace the [email protected] with your email address

mail("[email protected]", "Database Error", "There is a problem with the database!", "From: Db Error Watching");

//If you don't want to get emails comment out the above line of code
?>

Error Page HTML Part

<!-- Below this area is the html body of your error page you can design it as you like -->
<!DOCTYPE HTML>
<html>
<head>
<title>Uh-oh!</title>
</head>
<body>
<h1> There seems to be some problem here. Please visit this page again tomorrow. <br /> We apologize for the inconvenience this may cause you. </h1>
</body>
</html>

Full Code

<?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 Replace the [email protected] with your email address

mail("[email protected]", "Database Error", "There is a problem with the database!", "From: Db Error Watching");

//If you don't want to get emails comment out the above line of code
?>

<!-- Below this area is the html body of your error page you can design it as you like -->
<!DOCTYPE HTML>
<html>
<head>
<title>Uh-oh!</title>
</head>
<body>
<h1>There seems to be some problem here. Please visit this page again tomorrow. <br /> We apologize for the inconvenience this may cause you.</h1>
</body>
</html>

Thank you for reading post. Do leave your response in comments if it was of any help.

create free website wix below post

Further Related Readings

Copyrights © 2016 - Designzzz. All Rights Reserved