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.
This tutorial came just when I needed it, and is one of the things we can actually do at the file level when attempting to access the WP dashboard is impossible.
Much appreciated!
Now, is there an action to put this in your theme folder?
You know, I never thought about customizing that page. It’s a good idea because if a visitor comes across it at least it’ll fit the theme of your site and while they can’t see any info, maybe they can be amused.
The email seems like a good idea because it could help gauge how often visitors might hit that error. If it happens a lot then Houston we have a problem.
My only question goes back to the email. If a user lands on that page, I get an email. Will I get another email if that user reloads the page? Say the visitor lands, reloads in 10 seconds and continues. I don’t want to be spanned. Also, is the email hidden in the source code?