Skip to content

How to disable PHP errors in WordPress?

Sometimes, when working with WordPress, we may encounter PHP errors that are displayed on our website. While they can help developers diagnose problems, they are unnecessary for most users and can sometimes even reveal sensitive information that can be exploited by unauthorized parties. In this case, it is recommended to disable these errors. Let's look at how this can be done.

1. Editing the wp-config.php file

One of the easiest ways to disable PHP errors in WordPress is to modify the WordPress configuration file, known as wp-config.php. This file is located in the root directory of your WordPress installation. Be sure to back up your file before editing.

Open the wp-config.php file in any text editor, then search for the line below:

define('WP_DEBUG', true);

If it is set to true, it means that error reporting is turned on. To disable them, change the value true on false as shown below:

define('WP_DEBUG', false);

In addition, there is one more method to disable all errors and notifications by adding the following 3 lines under the above in wp-config.php, which will further disable all reporting:

ini_set('display_errors','Off'); ini_set('error_reporting', E_ALL ); define('WP_DEBUG_DISPLAY', false);

Save the file and close it. This change should disable PHP error reporting in WordPress.

2. Plugin usage

If you are not comfortable with editing files in your WordPress directory, you can use a plugin that will do it for you. Plugin named "WP Hide & Security Enhanceris one of the tools that allows you to control the display of PHP errors.

To use this plugin, install and activate it in your WordPress admin panel. Then go to the plugin settings panel. There you will find the "PHP errors" option. Just disable it to prevent PHP errors from displaying on your site.

3. Changing server settings

The last but more advanced method is to modify the .htaccess or php.ini file to change the PHP settings on the server. In the .htaccess file you can add the following lines:

php_flag display_errors off php_flag html_errors off php_value docref_root 0 php_value docref_ext 0

For the php.ini file, add the following lines:

display_errors = Off display_startup_errors = Off error_reporting

It's important to remember to disable bugs only on the production site and leave them enabled on the development site to make it easier to find and fix issues. Leaving debugging on on a production site will make us vulnerable to hackers.

Check out the offer of 1500+ Premium WordPress plugins and themes!