Best way to disable PHP errors in WordPress
It is quite simple to disable error reporting in wordpress because we just need to add a line of code at the bottom of our configuration file.
But while doing this we need to be careful about the correct placement. Sometimes we put it at wrong place and it is not working.
Turn off PHP error reporting is a step forward towards security of a wordpress website.
So, to hide or disable errors we just need to place this code at the bottom of our main wp-config.php file:
error_reporting(0); @ini_set(‘display_errors’, 0);
Now please note that we need to put the above code after below line of code which is already in your wp-config.php:
require_once(ABSPATH . 'wp-settings.php');
So your overall code must be :
/** Sets up WordPress vars and included files. */ require_once(ABSPATH . 'wp-settings.php'); error_reporting(0); @ini_set(‘display_errors’, 0);
Above is the correct placement. Putting error reporting code above than the wp-setting.php will not work for you because error reporting will be overridden by WordPress’s default settings. If still the above code not work for you then contact to your hosting provider.
Why we need to turn off PHP error reporting
Now the question arises why people say it is a good practice to turn of PHP error reporting for a wordpress website to make it more secure.
Yes they are right, as we know that generally errors are indicating the correct path where they occurs. If a hacker will see these errors, then he will be able to get idea about your directory structure and other useful path for him. Error information is always useful for a hacker, so it is better to disable error reporting from a live/production website.
Prevention is always better than cure, so move one step forward from the hacker and stay safe. 🙂
Leave a Reply