0

I'm trying to hide error messages on a WordPress installation on a shared hosting. I added the following code to my config.

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

This is pretty much what I find in any article regarding this topic. However, it doesn't work. I keep getting error messages. What could be the reason it isn't working for me?


A little update. One error I sometimes get is a "notice". When I keep all these three lines and put error_reporting to "0" as suggested in the answers, I still get the notice error.

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

However, when I comment the last 3 lines, the notice disappears:

define( 'WP_DEBUG', false );
//ini_set('display_errors','Off');
//ini_set('error_reporting', 0 );
//define('WP_DEBUG_DISPLAY', false);

Does that make any sense to anyone? What's happening here?

2
  • What error messages are you getting, and where? Dec 4, 2020 at 14:22
  • I'm getting this error message on a search result page: "Notice: Trying to access array offset on value of type bool in /www/htdocs/....php on line 55" for example. Dec 4, 2020 at 16:17

3 Answers 3

2

I believe that this line

ini_set('error_reporting', E_ALL );

will override other error settings. Will display all errors, even 'benign' ones, to the screen and error log file.

4
  • Are you sure about that? I read on multiple sites that you need to place this line in order to turn off error reporting, one of them being wpbeginner: wpbeginner.com/wp-tutorials/… Dec 8, 2020 at 14:20
  • No matter what I set there, it doesn't change anything. I still get the error messages. Dec 15, 2020 at 19:14
  • It depends on where you put the command. Is it in a template? Or your functions file? Or your child theme (because we don't want to edit the parent theme)? It may be that a command in the theme is overriding that command. I'd make a child theme (if not using one already), then modify the template that you are debugging to include the above command. Dec 16, 2020 at 0:55
2

You shoud use

ini_set('error_reporting', 0 );

instead of:

ini_set('error_reporting', E_ALL );

because E_ALL tell to show every error.

1
  • Well, on every website I find on the web that deals with the topic of hiding error messages in WordPress, they tell me to do it exactly as I posted it, with ini_set('error_reporting', E_ALL ), so I'm guessing it's correct like that. Anyway, no matter what I put there, it doesn't change anything. Apr 14, 2021 at 17:23
1

If your hosting php.ini is properly configured, is not necessary to use ini_set() in your wp-config.php when you are defining WP_DEBUG.

What is WP_DEBUG? It's a constant used in WP to determine what error notice settings to apply. When WP loads, one of the functions that is run on every load is wp_debug_mode(). I highly suggest you review what it does so you know why you originarily do not need to use ini_set() - because it's already being done in wp_debug_mode(). So what you're doing by adding this to your wp-config.php is the equivalent of flipping the switch on/off/on/off over and over.

When WP_DEBUG is set to true, it sets error_reporting( E_ALL ). Otherwise, error_reporting() is set to a lesser value. You should not manually set this to 0 unless you know what you're doing - otherwise, you're shutting off all error reporting, which will make it hard when you actually need to debug something but forgot that you turned off all notices. Unless you really have a need to do so, just let WP handle setting the error_reporting() value.

Next, when WP_DEBUG is true, it handles the display of errors based on the WP_DEBUG_DISPLAY value. If it's true, then ini_set() is run to set 'display_errors' to "1", which will display errors on the screen. If WP_DEBUG_DISPLAY is set to false, it will set 'display_errors' to "0" which will suppress display of any errors.

I hope this didn't confuse the issue, and I hope that you can see why the last set you had (where all but WP_DEBUG was commented out) suppressed the messages.

If you want error messages turned off, just set WP_DEBUG and WP_DEBUG_DISPLAY to false, and get rid of the ini_set() lines you have.

1
  • I did what you said in your last sentence, but it doesn't work. I still get warnings. Apr 14, 2021 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.