WP_DEBUG is a useful WordPress PHP constant that can be used to trigger the “debug” mode throughout WordPress. When it’s set to “true” in wp-config.php, all PHP errors, notices and warnings, as well as all notices about deprecated functions and arguments that are being used within WordPress site, are been printed on the screen as part of the output and display in the HTML of the web pages.

The problem is that everybody, including visitors to your website, will always be able to see the debug messages. And it makes the website looks awful. In addition, WP_DEBUG overrides the behavior of PHP regardless of whether it’s default settings or user settings, which can be only displaying fatal errors and/or showing a white screen of death when errors happened.

WordPress provides a workaround that forces all debug information to be logged and saved to a log file, and prevents the debug information from printed on screen. The trick is also useful if you need to view debug info generated off-screen such as during an AJAX event or WP-cron execution.

The trick to hide the WordPress debug messages from appearing on screen and save the log messages to a log file depends on WP_DEBUG_LOG and WP_DEBUG_DISPLAY constants, both of which can be defined independent of each other, but only effective when WP_DEBUG is set to true.

Use the following code in wp-config.php file, which log all errors, notices and warnings to a file called debug.log in the /wp-content/ directory and suppress all debug messages from displaying on the web pages’ HTML.

define('WP_DEBUG', true);          // Enable WP_DEBUG mode
define('WP_DEBUG_LOG', true);      // Enable logging to the /wp-content/debug.log file
define('WP_DEBUG_DISPLAY', false); // Disable display of errors, notices and warnings on screen
Note
If you haven’t disabled the display and printing of PHP errors on screen through php.ini configuration file, you can add the following code in wp-config.php too to suppress all PHP error messages to ensure that web pages are always clean from unnecessary error messages:

@ini_set('display_errors',0);