For many WordPress developers, WordPress’ built-in DEBUG MODE is their number one debugging tool – simple enough to setup yet powerful enough to detect almost any coding error.

For beginner developer, you should almost always enable DEBUG MODE on your development site to monitor your coding.

To enable Debug Mode on WordPress, include the following code to your wp-config.php, above the line
/* That’s all, stop editing! Happy publishing. */ :


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

/* That's all, stop editing! Happy publishing. */

  • WP_DEBUG – true or false. True to enable DEBUG MODE.
  • WP_DEBUG_DISPLAY – true or false. True to display error/warning on website. False to hide.
  • WP_DEBUG_LOG – true or false. True to log error/warning in debug.log file that you can find at /wp-content/debug.log

WP_DEBUG or WP_DEBUG_LOG is not working?

For some hosting, just adding the above code into wp-config.php might not be sufficient. In most cases, it’s due 4 possible situations:

1. PHP’s Error Reporting is Disabled

Some hosting companies disabled PHP’s error reporting function by default. More specifically, display_errors is set to 0 (if you’re enabling WP_DEBUG_DISPLAY) or log_errors is set to 0 (if you’re enabling WP_DEBUG_LOG) by the hosting companies, and you can’t enable them dynamically/runtime-style via PHP code. (When WP_DEBUG is enabled, WordPress actually will tries to set both value to 1 if they’re 0.)

In this case, you’ll to enable them via php.ini or .user.ini file.

php.ini and .user.ini are config file for PHP. Create a file named .user.ini and upload it to your hosting website root folder (usually website root folder will be named /public_html/) and then insert the following code:

If you would like to enable debug log (for WP_DEBUG_LOG):

log_errors = On

If you would like to display error/warnings (for WP_DEBUG_DISPLAY):

display_errors = On

If it doesn’t work, rename .user.ini to php.ini. If it still doesn’t work, you’ll need to contact your hosting company’s support regarding this issue.

2. Plugins overriding Error Reporting

There could be a conflicting plugin on your website that is overriding the settings for PHP’s error reporting function. Disable the plugins one by one to detect the culprit.

3. File Permission Issue

Your website does not have the permission to create the file debug.log at /wp-content/ folder. You’ll need to contact your hosting company’s support to assist with this issue.

4. error_log is set to a different path (for WP_DEBUG_LOG)

If debug.log is not created automatically at /wp-content/, it’s possible that the location of the log file has already set to somewhere else. In the .user.ini or php.ini, append the following code:

error_log = "/home/username/public_html/wp-content/debug.log"

Replace the file path with the correct path to your debug.log So, with log_errors:

log_errors = On
error_log = "/home/username/public_html/wp-content/debug.log"

If none of the above solution works, you really need to contact your hosting company.

***

If DEBUG_MODE is enabled successfully, you should be able to see error messages on your website or in the debug.log. But do note that this can only help you detect error in your PHP/WordPress codes, not the performance bottleneck (that will be for another post in the future).