How do I enable WordPress WP_DEBUG?

Enabling the WordPress debug log (aka WP_DEBUG) can be very useful — your theme and/or some badly coded plugins may be generating hundreds of PHP errors, and you would never know unless you enabled the WordPress debug log.

To enable the WordPress debug log, without displaying the errors to your visitors, add the following to your wp-config.php file. Make sure you do not already have a define() for WP_DEBUG in your wp-config.php file (as constants can only be defined once). If you do, you can safely remove it and replace it with the following lines.

You can easily turn on/off the WordPress debug log by changing WP_DEBUG‘s value from true to false.

Any WordPress or PHP error messages will be saved in the wordpress/wp-content/debug.log file by default. If you have several badly coded and/or old plugins and themes that generate a lot of errors, then also make sure you clear the contents / rotate this file regularly, as it could grow large enough to fill a filesystem. In all cases, you should endeavour to resolve all warnings and errors in the debug.log file — the debug.log file should remain empty — always.

The default location of the debug.log file can be changed by specifying a file path for the WP_DEBUG_LOG value.