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.
- Create theme-error-handler.php file on your theme or plugin directory and include it.
- Copy the contents as provided in the source code below.
- Setup WP_DEBUG_DISPLAY in wp_config.php to true.
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.