Categories
WordPress

Custom Error for WordPress

Tested up to 2.8.5

There’s nothing I do I hate more than finding an error after hours happening.

That was happening in one of my blogs quite often, and I couldn’t trace properly…

This WP hack will allow you to control the 500 error and been notified every time this happens.

How to?

First – Create in the same folder of you theme a file called error.php. In this file I recommend to you to add only HTML code with a friendly error message.

Second – Edit this file in your favorite text editor /wp-includes/wp-db.php

Third – Find this function “function bail($message)”

Fourth – Instead of the current function I recommend to comment the function and paste this (change what’s needed)

function bail($message) {
/*
custom error page hack
shows a custom error page and emails error instead of showing the default wordpress database error page
*/
   include('wp-content/themes/YOUR_THEME_HERE/error.php');
   mail('your@email_here.com', 'WordPress Error!', $message);
   die;
/* end custom error page hack */
}

This must be used careful and under your own risk. Also be aware of mass email sending/receiving.