Turning on WordPress debug mode safely: WP_DEBUG and the log

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.
4 Read the error and act: Common WordPress errors, and if it is memory, give it more memory. The server’s PHP log is a different one, and complements it: The PHP error log.
5 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.
If the site will not even open because of the error, deactivate the plugins first: Disabling plugins, even when you cannot get in.

The log does not help and you still do not understand? Open a ticket with the last lines of debug.log (no passwords).

Open a support ticket

SEE ALSO

Common WordPress errors: white screen, critical error and how to find the cause

Where the PHP error log is, how to read it, and the errors you will see most

Giving WordPress more memory

Rebuilding the wp-config.php connection

RECOMMENDED PRODUCT

WordPress hosting

One-click install, updates handled, and speed that holds up. from $5.36/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?