PHP comments and messages are helpful for WordPress developers to “debug” issues in the code they or others have written. Of course, it wouldn’t be professional if these were displayed for site visitors, so in this short post, we’ll see how to prevent the display of PHP errors in WordPress sites.
Why and When Should You Disable PHP Error Display in WordPress?
The PHP errors you see in WordPress are usually warnings and notices. They are not critical errors in the code, meaning internal server errors, syntax errors, and the like that prevent the site from loading.
PHP warnings and notices are a type of error that doesn’t cause the site to fail on loading. The purpose of these warnings and notices is to help developers debug the code they wrote. Plugin and theme developers use them to check compatibility and best coding practices.
These can also appear on the Frontend and be visible to visitors on your site.
However, if you are not developers of themes or plugins, you must ensure that these errors are not visible to users.
Disabling PHP Errors on WordPress Sites
To disable the display of PHP errors and warnings in WordPress, go to the wp-config.php
file in the root directory of your site and look for the following line:
define('WP_DEBUG', true);
It’s possible that WP_DEBUG
is already set to false
:
define('WP_DEBUG', false);
Either way, you need to replace this line with the following code to hide those PHP errors and warnings:
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false);
Displaying PHP Errors in WordPress
To display those PHP errors and warnings, replace the last code snippet with the following lines:
define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', true);
For more information on error monitoring and debugging in WordPress, you can check the post on Why it’s better to use WP_DEBUG_LOG when developing WordPress sites.