When define(‘WP_DEBUG’, false) fails to meet expectations

When managing errors and debugging in WordPress, several constants and configuration settings play a crucial role.

When managing errors and debugging in WordPress, several constants and configuration settings play a crucial role. The WP_DEBUG constant is a cornerstone, allowing developers to toggle the debugging mode on or off in the wp-config.php file. When set to true, it displays PHP errors, warnings, and notices directly on the screen, aiding in identifying and addressing issues during development.

To complement WP_DEBUG, additional constants come into play:

WP_DEBUG_LOG: When set to true, this constant instructs WordPress to log errors, warnings, and notices to a /wp-content/debug.log file. This is invaluable for troubleshooting, as it keeps a record of errors without exposing them to users.

Instead, you have the option to assign it a valid file path to store the file in a different location. i.e.

define( 'WP_DEBUG_LOG', '/logs/wp-errors.log' );

WP_DEBUG_DISPLAY: This constant controls the display of errors on the screen. Setting it to false prevents PHP errors from being visible to site visitors, maintaining a polished and secure user experience.

Please bear in mind that for both WP_DEBUG_LOG and WP_DEBUG_DISPLAY to take effect, WP_DEBUG must be enabled (set to true).

INI_SET

In certain hosting environments, such as shared hosting with cPanel, directly using:

define('WP_DEBUG', false); 

or

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

might not suffice. As an alternative, the ini_set function allows fine-tuning of PHP configurations:

ini_set('log_errors', 'On');
ini_set('display_errors', 'Off');
ini_set('error_reporting', E_ALL);

These ini_set constants enhance the control over error handling:

  • log_errors: When set to ‘On‘, it enables the logging of PHP errors to a file.
  • display_errors: Setting this to ‘Off‘ ensures that PHP errors are not displayed on the screen, enhancing security and professionalism.
  • error_reporting: This constant defines the level of error reporting, with E_ALL encompassing all types of errors for comprehensive debugging.

By understanding and appropriately configuring these constants, developers can tailor error handling to their specific needs, ensuring a smooth and secure WordPress website.

Good read:

Nikola Stulic

Father of two beautiful girls. WordPress developer trapped inside the mind of a math teacher (and vice versa). Often doodles the Greek letter Xi. Loves to wear suits and ties.

WordPress contributor, educator, translator. WordCamp Europe organizer.

1 comment

  • A safe way to use Debug is to allow for defining it in the wp-config file. This gives you freedom to turn on the modules you need, for when you need them, but mostly/only for development or quick discovery on a production site.

    Never leave debug running (true) when not troubleshooting.

    define( ‘WP_DEBUG’, true );
    if ( WP_DEBUG ) {
    define( ‘WP_DEBUG_LOG’, true );
    define( ‘WP_DEBUG_DISPLAY’, false );
    @ini_set( ‘display_errors’, 0 );
    define(‘SAVEQUERIES’, true);
    }

    Setting `display_errors` to 1 will show errors on front. Same with `WP_DEBUG_DISPLAY` when set to true. @see http://snippwiki.com/public-snippet.php?pub_id=41

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.