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 WordPress Error Handler script, you can view the call stack of the errors you get.


  1. Create wp-error-handler.php file in your wp-content/mu-plugins directory.
  2. Copy the contents as provided in the source code below.
  3. Setup WP_DEBUGWP_DEBUG_DISPLAY, or WP_DEBUG_LOG in wp_config.php to true.

Setting it Up

Below is the code provided you need to set up. In your wp-content/mu-plugins directory create a file wp-error-handler.php. WordPress will automatically load the file as it is a Must Use Plugin. You may read more about must use plugins here.

You have to define the constant WP_DEBUG as true to enable the error handler. To display errors on your web browser, set WP_DEBUG_DISPLAY as true.

You also have the choice to write the errors to the WordPress’s debug 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.

Example Screenshot

Image Taken at Suzhou, Jiangsu, China, edited with Prisma AI.