Solution 2: Temporary Debugging by Modifying the Fatal Error Handler
WordPress masks fatal errors behind a generic message:
“The site is experiencing technical difficulties. Please check your email for instructions.”
These errors are handled in /wp-includes/class-wp-fatal-error-handler.php inside a try..catch block, which prevents the actual error message from being displayed.
A temporary debugging solution is to modify the handle() method to bypass the try..catch block and log the error message. Important: This modification should only be used for debugging and must be undone before putting the site into production.
public function handle() {
if ( defined( 'WP_SANDBOX_SCRAPING' ) && WP_SANDBOX_SCRAPING ) {
return;
}
// Detect the error
$error = $this->detect_error();
if ( ! $error ) {
return;
}
// Log the error message
error_log( $error["message"] );
return;
// Optional: Load default textdomain if necessary
if ( ! isset( $GLOBALS['wp_locale'] ) && function_exists( 'load_default_textdomain' ) ) {
load_default_textdomain();
}
if ( ! is_multisite() && wp_recovery_mode()->is_initialized() ) {
wp_recovery_mode()->handle_error( $error );
}
// Display the PHP error template if headers not sent
if ( is_admin() || ! headers_sent() ) {
$this->display_error_template( $error );
}
// The original try..catch block is commented out for debugging
// } catch ( Exception $e ) {
// // Catch exceptions and remain silent
// }
}
Notes:
1. The error_log() function will log errors to wp-content/debug.log if this line exists in your wp-config.php:
define( 'WP_DEBUG_LOG', true );
2. Otherwise, errors will go to your server’s Apache/PHP error log.
3. This is a simple, quick way to see fatal errors. There are other approaches, but this is effective for immediate debugging.