search ]

How to Prevent the Display of PHP Errors in WordPress

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('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.

Roee Yossef
Roee Yossef

I develop custom WordPress themes by design. I love typography, colors & everything between, and aim to provide high performance, seo optimized websites with a clean & semantic code.


Leave a Comment

Add code using the buttons below. For example, to add PHP click the PHP button & add the code inside the shortcode. Typo? Please let us know...