Engineering
A Better Way to Show WordPress Database Errors
A cleaner approach to displaying WordPress database errors for easier debugging during development.
1 min read
If you visit this website often, you may have noticed some downtime (due to issues with the Amazon Cloud servers). I got tired of seeing that ugly default error message, so I decided to override the WordPress database error message with something friendlier for users. To do this, I followed a blog post by Jeff Starr, and it worked like a charm.
Better way to display WordPress Database Error
Create a file named db-error.php in the wp-content directory and paste in the following code. Feel free to style it however you like.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Terribly sorry :(</title>
</head>
<body>
<div class="container">
<h1>Terribly sorry <span>:(</span></h1>
<p>I am sorry, looks like the Amazon Cloud Servers aren't responding or are having some technical issues right now.</p>
<p>Sometimes refreshing the browser may work, hit on the refresh button or press CMD + R / CTRL + F5</p>
</div>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'YOUR GOOGLE ANALYTICS ID']);
_gaq.push(['_setDomainName', 'YOUR DOMAIN']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
_gaq.push(['_setCustomVar', 1, '500 Error', 'Error site Loading', 1]);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>
Feel free to share it anywhere you like.
Related reading
-
Trigger and Shoot – Slim WordPress plugin
Trigger and Shoot: a slim, lightweight WordPress plugin for triggering actions on post events.
-
WordPress: How to trigger the Post publish event
How to hook into and trigger the WordPress post-publish event for custom automation.
-
How to Enjoy Programming in the LLM Era
Why coding feels less fun since AI assistants arrived, what METR's productivity trial and Stack Overflow's trust data actually show, and the personal habits and team practices that keep comprehension of your own system yours.