最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

debug - Why does WordPress keep showing me error messages?

programmeradmin0浏览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?

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?

Share Improve this question edited Dec 14, 2020 at 10:32 TheKidsWantDjent asked Dec 4, 2020 at 13:21 TheKidsWantDjentTheKidsWantDjent 3154 silver badges20 bronze badges 2
  • What error messages are you getting, and where? – Jacob Peattie Commented 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. – TheKidsWantDjent Commented Dec 4, 2020 at 16:17
Add a comment  | 

3 Answers 3

Reset to default 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.

You shoud use

ini_set('error_reporting', 0 );

instead of:

ini_set('error_reporting', E_ALL );

because E_ALL tell to show every error.

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.

发布评论

评论列表(0)

  1. 暂无评论