Grow your CSS skills. Land your dream job.

Last updated on:

Custom Database Error Page

Put a file called "db-error.php" directly inside your /wp-content/ folder and WordPress will automatically use that when there is a database connection problem.

<?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>

Reference URL

Comments

  1. We have a free plugin to allow templates for the error pages, such as comment submission errors. <a href=”mudslidedesign.co.uk/blog/theme-able-wordpress-error-page”>mudslidedesign.co.uk/blog/theme-able-wordpress-error-page, let us know what you think of it.</a>, let us know what you think of it.

  2. The only problem I see with this is when your database stops responding for a few minutes.
    If you activate the email notification you’ll get a lots of emails when a single one would have been enough.
    Other then that it’s a great tip.

    • You could always create a session variable when the email is sent so you only get one email to notify you if there is a problem. Good tip, thanks Chris :)

Leave a Comment

Posting Code

  • Use Markdown, and it will escape the code for you, like `<div class="cool">`.
  • Use triple-backticks for blocks of code.
    ``` 
    <div>
      <h1>multi-line block of code</h1>
      <span>be cool yo.</span>
    </div>
    ```
  • Otherwise, escape your code, like <code>&lt;div class="cool"&gt;</code>. Markdown is just easier though.

Current ye@r *

*May or may not contain any actual "CSS" or "Tricks".