Better Error Handler for WordPress Debugging

As a theme or plugin developer, WordPress debugging may be a pain as some errors may not be specific, especially if you have a giant class->function call stack. With this simple script, you can view the call stack of the errors you get.

Overview

  1. Create theme-error-handler.php file on your theme or plugin directory and include it.
  2. Copy the contents as provided in the source code below.
  3. Setup WP_DEBUG_DISPLAY in wp_config.php to true.

Download Fork on GitHub

Setting it Up

Below is the code provided you need to set up. Simply create a file theme-error-handler.php (or anything like that). Then use the PHP function ‘include ‘ in your theme’s function.php or in your plugin’s core PHP file.

Note that you have to enable WP_DEBUG and WP_DEBUG_DISPLAY constant to enable the error handler. You may simply add “define (WP_DEBUG_DISPLAY, true);” in  your wp_config.php file.

You also have the choice to write the errors to the log file (/wp-content/debug.log) by enabling WP_DEBUG_LOG constant.

In an event of an error, a message similar to the screenshot below will be displayed.

Better Error Handler for WordPress - Screenshot

Comments