Turning on WordPress debug mode safely: WP_DEBUG and the log
· 30 views· 3 min read
The short answer: when the site shows a white page or a “critical error” without saying why, debug mode makes WordPress write the error to a file. You switch it on with three lines in wp-config.php. But there is a rule: switch it off when you finish, and do not leave errors in view of visitors.
The three lines
Line
What it does
define( 'WP_DEBUG', true );
Switches on debug mode: WordPress starts recording warnings and errors.
define( 'WP_DEBUG_LOG', true );
Writes them to the file wp-content/debug.log.
define( 'WP_DEBUG_DISPLAY', false );
Does not show them on screen, so visitors do not see them.
Step by step
1
Take a copy of wp-config.php. A typing mistake in this file takes the site down.
2
Open wp-config.php (cPanel File Manager) and look for the line that says “WP_DEBUG”. If it exists with the value false, swap it for the three lines above; if not, put the three before the line “That’s all, stop editing”.
3
Repeat the problem (open the page that fails) and then open the file wp-content/debug.log: the last line usually says the file and the plugin or theme at fault.
Switch everything off at the end: back to false, and delete debug.log.
The debug.log file is public by default: whoever knows the address (your-domain.com/wp-content/debug.log) can read it, and it shows paths and plugin names. So: switch the mode off when you finish, delete the file and, if you must leave it on, protect it. Never leave WP_DEBUG_DISPLAY true on a site with visitors.