1

I'm getting errors, warnings and notices being displayed on a site. Those include things like filesystem paths, SQL queries and wpdb prefixes, which I don't think it's particularly good to have them being displayed to all visitors.

I have fixed the cause of the issue, but I want to prevent these error messages from being displayed on the live site. Turning WP_DEBUG_DISPLAY off hides the errors, but the warnings and notices remain. How do I hide those?

7
  • 3
    Do not hide those messages. Fix them instead. Disk full is a very serious problem that you have to address.
    – fuxia
    Mar 29, 2019 at 17:30
  • In my opinion showing environment data (filesystem paths, SQL queries and wpdb prefixes) isn't exactly desirable. Fixing issues is important, but there should be some sort of automated monitoring workflow instead of relying on the kindness of site visitors. Or is it a good practice to have WP_DEBUG_DISPLAY turned on on production? Mar 29, 2019 at 18:03
  • You should set up a password protected staging environment where all errors, warnings and notices are displayed while on production debug output is disabled. Fix everything on stage and copy to production then.
    – Luckyfella
    Mar 29, 2019 at 18:41
  • @Luckyfella "Everybody has a testing environment. Some people are lucky enough enough to have a totally separate environment to run production in". Mar 29, 2019 at 18:42
  • 1
    @fuxia Sorry, but you're wrong. Such messages should be never displayed on production server. They can (and should) get logged, but never, never shown on the site. And yes - of course you should fix them, if it's possible (not always it is - even WordPress itself causes some notices sometimes). Mar 29, 2019 at 18:42

2 Answers 2

6

As many have already commented, it is better to fix the source of the issue than to hide the messages. That said, these types of messages should never be displayed on production server but, since you just never know, it is also a good idea to disable them on all servers (local development machine, development machines, etc.).

We use the following settings in wp-config.php to disable the display of all warnings, notices, errors, etc. and then use tail -f wp-content/debug.log to see the errors as we work:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Sometimes Notices don't include a backtrace so you can't see what's causing the message. Please see my answer to a similar question as it includes details on how to get a backtrace for such messages.

If you are still seeing warnings and info and such and you've followed my advice in this answer, then it is likely a plugin or the theme itself is re-enabling the display of warnings and info.

WP_DEBUG_DISPLAY is a constant that tells WordPress to run the following code:

if ( WP_DEBUG_DISPLAY ) {
    ini_set( 'display_errors', 1 );
} elseif ( null !== WP_DEBUG_DISPLAY ) {
    ini_set( 'display_errors', 0 );
}

This code is in wp-includes/load.php and is, if not the first, one of the very first files included in the WordPress bootstrapping procedure. The function that this code appears in is called in wp-settings.php which is the first file included after wp-config.php. This code is called before plugins are loaded and executed.

If a plugin producer has ini_set( 'display_errors', 1 ) in their code, it will override what you've got in wp-config.php and continue showing PHP errors, warnings, info, etc. There is no way, really, to override this. Try searching your entire plugins folder for ini_set to see if you can spot the culprit. You should probably also check your theme while you are at it.

1
  • Doing a Troubleshooting with the 'Health Check & Troubleshooting' plugin may be another fast option to see whether other plugin/theme does this override? I'm just asking, as im not a guru of the hooking priority with plugins vs WP Core parts for debugging. Aug 19, 2020 at 16:41
-1

As others have already said, it's very important to fix the underlying issues causing the error messages to show up.

In my opinion, it's also important to have these errors and warnings showing up on development and homologation environments, but not on production, for a variety or reasons.

I was able to remove notices and warnings from the production environment by placing the following line into wp-config.php:

ini_set('display_errors','Off');

Even with WP_DEBUG turned off, a few warnings were still being shown.

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.