Listen to this article
14 minute listen
Narrated by an AI voice · 13 chapters
AI Overview
To enable WordPress debug mode, edit wp-config.php and set WP_DEBUG and WP_DEBUG_LOG to true and WP_DEBUG_DISPLAY to false. Errors are then saved to wp-content/debug.log instead of shown to visitors. Read the log to find the plugin or theme at fault, then set WP_DEBUG back to false.
Key takeaways
- WP_DEBUG is the master switch; WP_DEBUG_LOG and WP_DEBUG_DISPLAY control where errors go.
- On live sites, log errors and hide them from visitors with WP_DEBUG_DISPLAY false.
- debug.log lives in wp-content by default; move it outside the web root or block access.
- The file path in each log entry tells you which plugin or theme caused the error.
- Turn debugging off and delete debug.log as soon as you have found the problem.
Free WordPress plugin
Know which plugin update broke your site.
The free MyKavo plugin watches your site through every plugin, theme and core update, and tells you which one caused a change, before your visitors find it.
- Records every plugin, theme and WordPress update
- Checks your key pages right after each update and names the one that broke something
- One-click rollback when an update goes wrong, free
- Changes, alerts and before-and-after proof inside wp-admin
Free on WordPress.org · WordPress 6.2+ · PHP 7.4+ · The check after each update comes with every paid plan
Summarize with AI
Opens the assistant in a new tab with a link to this post.
On this page
WordPress debug mode turns hidden PHP errors into messages you can read, so you can find out why a page is blank, a plugin is crashing or your site shows "There has been a critical error on this website." You switch it on with a few lines in wp-config.php, and the safest setup writes errors to a log file instead of showing them to visitors.
This guide covers every debugging constant (WP_DEBUG, WP_DEBUG_LOG, WP_DEBUG_DISPLAY, SCRIPT_DEBUG and SAVEQUERIES), where debug.log lives and how to move it, how to keep the log private, how to read it, and how Query Monitor and recovery mode help. It ends with how to turn debugging off again, which is the step people forget.
Debugging a site that broke after an update? The free MyKavo WordPress plugin checks your pages after every plugin, theme and core update and names the update when something broke. Start monitoring free.
Quick answer: how to enable WordPress debug mode#
- Back up
wp-config.php, then open it via SFTP, your host's file manager or SSH. - Find the line
define( 'WP_DEBUG', false );(or add it if it's missing). - Replace it with the debug block below, above the line that says "That's all, stop editing!"
- Reload the broken page, then open
wp-content/debug.logto read the errors. - Fix the cause (often a plugin, theme or PHP version issue).
- Turn debugging off by setting
WP_DEBUGback tofalseand deletingdebug.log.
// Enable WordPress debug mode, log errors, hide them from visitors
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
This is the recommended setup for a live site: errors go to the log, not to the screen.
What WordPress debug mode does#
By default WordPress hides PHP errors, warnings and notices. That keeps visitors from seeing technical messages, but it also means a broken page gives you nothing to go on.
WP_DEBUG is the master switch. When it's true, WordPress reports all PHP errors, warnings, notices and deprecation messages, including WordPress's own notices about deprecated functions. The other constants control where those messages go and what extra information WordPress collects.
The official reference is the Debugging in WordPress page in the WordPress developer documentation.
Every WordPress debugging constant#
| Constant | Default | What it does |
|---|---|---|
WP_DEBUG | false | Master switch. Reports all PHP errors, warnings and notices. |
WP_DEBUG_LOG | false | Saves errors to wp-content/debug.log, or to a custom path. Only works when WP_DEBUG is on. |
WP_DEBUG_DISPLAY | true | Shows errors on the page. Set to false on live sites. |
SCRIPT_DEBUG | false | Loads the unminified versions of WordPress core CSS and JavaScript. |
SAVEQUERIES | false | Stores every database query, with timing and the calling function, for inspection. |
WP_DEBUG#
define( 'WP_DEBUG', true );
On its own, this shows errors on screen, because WP_DEBUG_DISPLAY defaults to true. That's fine on a local or staging site, but not on a live site, where error messages can reveal file paths and break page layouts for visitors.
WP_DEBUG_LOG#
define( 'WP_DEBUG_LOG', true );
This writes every error to wp-content/debug.log. The file is created the first time an error is logged, so if it doesn't exist yet, reload the broken page.
Use a custom log path. Since WordPress 5.1, you can pass a file path instead of true:
define( 'WP_DEBUG_LOG', '/home/youruser/logs/wp-errors.log' );
Pick a folder outside your public web root (outside public_html or www), so the file can't be downloaded from a browser. The folder must exist and be writable by PHP, or nothing will be logged.
WP_DEBUG_DISPLAY#
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
Setting this to false stops WordPress from printing errors into your pages. The ini_set line makes sure PHP itself doesn't display them either, in case your server's PHP configuration has display_errors turned on.
SCRIPT_DEBUG#
define( 'SCRIPT_DEBUG', true );
WordPress normally loads minified versions of its core CSS and JavaScript. SCRIPT_DEBUG loads the full development versions instead, which makes JavaScript errors in the browser console readable. Use it when debugging the block editor, admin screens or core scripts, and switch it off afterward, since the unminified files are larger.
SAVEQUERIES#
define( 'SAVEQUERIES', true );
This stores every database query in $wpdb->queries, along with how long it took and which function ran it. It's useful for finding slow queries but adds overhead to every page load, so only enable it briefly, ideally on staging. Query Monitor (below) displays the same information in a readable panel.
Try it on your site · free
Check your own page's meta tags
Title, description, canonical and robots - including an accidental noindex - in a few seconds.
Where to put the code in wp-config.php#
wp-config.php sits in your WordPress root folder, the same folder that contains wp-admin and wp-content.
- Download a copy first so you can restore it if you make a typo. A single missing semicolon can take the whole site down.
- Search for
WP_DEBUG. Most installs already havedefine( 'WP_DEBUG', false );. Edit that line rather than adding a second definition, which causes a "constant already defined" warning. - Add the other constants directly below it, and above the comment that says
/* That's all, stop editing! Happy publishing. */. Anything placed after the line that loadswp-settings.phpruns too late to take effect.
Enable debug mode with WP-CLI#
If you have SSH access, WP-CLI edits wp-config.php for you:
wp config set WP_DEBUG true --raw
wp config set WP_DEBUG_LOG true --raw
wp config set WP_DEBUG_DISPLAY false --raw
The --raw flag writes true and false as PHP values instead of text strings, which matters: the string 'false' would actually count as true.
Some managed hosts also offer a debug toggle in their dashboard. It does the same thing; check your host's help center for where they write the log.
How to read debug.log#
Open the log with your host's file manager, download it via SFTP, or follow it live over SSH:
tail -f wp-content/debug.log
Each line has a timestamp, an error type, a message, and the file and line number where it happened. The file path is the most useful part, because it tells you which plugin or theme is responsible:
[23-Nov-2026 10:42:17 UTC] PHP Fatal error: Uncaught Error: Call to undefined function example_function() in /var/www/html/wp-content/plugins/example-plugin/includes/init.php:42
Here the problem is inside wp-content/plugins/example-plugin. Paths under wp-content/themes/ point to a theme.
What the error types mean#
| Type | Severity | What to do |
|---|---|---|
| Fatal error | Stops the page from loading | Fix first. Usually causes the critical error message or a white screen. |
| Warning | Code continued, but something went wrong | Investigate; often a sign of a coming failure. |
| Notice | Minor issue, such as an undefined variable | Usually safe to ignore on production; report to the developer. |
| Deprecated | Code uses something that will be removed | Update the plugin or theme. Common after a PHP upgrade. |
Common fatal errors and what they point to:
- "Allowed memory size exhausted": raise the WordPress memory limit or find the plugin using too much.
- "Call to undefined function" or "Class not found": a plugin is missing a dependency, or a plugin or theme is incompatible with your PHP or WordPress version.
- "Cannot redeclare": two plugins define the same function. Our plugin conflict guide shows how to isolate it.
Clear the log before you reproduce the problem. Old entries make it hard to see which errors belong to the issue you're chasing. Delete or empty debug.log, reload the broken page once, then read what was written.
Keep debug.log private#
The default location, wp-content/debug.log, is inside your public web folder. Anyone who guesses the URL can download it and see file paths, plugin names and sometimes data passed in errors. WordPress's Site Health screen warns about this when logging is on.
The best fix is a custom path outside the web root, shown above. If you must keep the default location, block access to the file.
On Apache (most shared hosting), add this to the .htaccess file in your WordPress root:
<Files "debug.log">
Require all denied
</Files>
On Nginx, add this inside your site's server block and reload Nginx:
location ~* /debug\.log$ {
deny all;
}
Then try to open https://yourdomain.com/wp-content/debug.log in a private window. You should get a 403 Forbidden response, not the file. Our WordPress security guide covers other files worth locking down.
Query Monitor: debugging inside wp-admin#
Query Monitor is a free plugin that adds a debugging panel to the admin bar, visible only to administrators. It shows:
- PHP errors, warnings and notices on the current page, with the plugin or theme responsible.
- Every database query, with slow and duplicate queries highlighted.
- HTTP API calls to external services, and whether they failed.
- Hooks, enqueued scripts and styles, and the template file being used.
Query Monitor works without editing wp-config.php, which makes it a good first step when the site still loads. Deactivate it when you're done, since it adds overhead to admin page loads.
Recovery mode: when you can't reach wp-admin#
Since WordPress 5.2, when a plugin or theme causes a fatal error, WordPress shows a critical error message and emails the site's admin address a recovery mode link. Clicking it logs you in with the broken plugin or theme paused, so you can deactivate or update it.
- The email goes to the address in Settings > General, unless you set a different one with
define( 'RECOVERY_MODE_EMAIL', 'you@example.com' );. - If the email never arrives, your site may not be able to send mail at all. See our guide to WordPress not sending email.
- No email and no wp-admin access? Rename the plugin's folder in
wp-content/pluginsvia SFTP to deactivate it, then usedebug.logto confirm the cause.
Turn debug mode off when you're done#
Leaving debugging on is a common mistake. The log keeps growing, can fill your disk, and exposes information about your site.
- Set
WP_DEBUGback tofalseinwp-config.php(or runwp config set WP_DEBUG false --raw). - Remove or disable
SCRIPT_DEBUGandSAVEQUERIESif you added them. - Delete
debug.logonce you've saved anything you need. - Check Tools > Site Health > Info under WordPress Constants to confirm the debug values are off.
For ongoing error tracking on a live site, server-level PHP error logs from your host are a better long-term option than leaving WP_DEBUG on.
How to catch errors before visitors do#
Debug mode helps once you know something is wrong. The hard part is knowing. Many PHP errors don't take a whole site down: they break one template, a product page, or a checkout step, while the homepage looks fine.
MyKavo watches the pages you choose and re-scans them on a schedule (weekly on the Free plan, daily on paid plans). It alerts you when a page's HTTP status changes (for example from 200 to 500), when an H1, title or important element disappears, or when the page changes visually, with before-and-after screenshots and a severity so you know what to fix first. The free MyKavo WordPress plugin runs those checks after every plugin, theme and core update and names the update that broke something, which tells you exactly where to start reading debug.log.
Frequently asked questions#
Frequently asked questions
How do I enable debug mode in WordPress?
Edit wp-config.php and set define( 'WP_DEBUG', true ); above the "That's all, stop editing!" line. On a live site, also set WP_DEBUG_LOG to true and WP_DEBUG_DISPLAY to false so errors go to a log file instead of the screen.
Where is the WordPress debug log?
By default it's wp-content/debug.log, created the first time an error is logged. If WP_DEBUG_LOG is set to a file path instead of true, the log is written to that path.
Is it safe to enable WP_DEBUG on a live site?
Yes, briefly, if you log errors and hide them from visitors with WP_DEBUG_DISPLAY set to false. Protect or move debug.log so it can't be downloaded, and turn debugging off as soon as you've found the problem.
Why is debug.log not being created?
Either no error has happened since you enabled it, WP_DEBUG is still false, the constants were added below the line that loads wp-settings.php, or PHP can't write to the folder. Reload the broken page and check file permissions.
What is the difference between WP_DEBUG and WP_DEBUG_LOG?
WP_DEBUG turns error reporting on. WP_DEBUG_LOG decides whether those errors are saved to a log file. WP_DEBUG_LOG does nothing unless WP_DEBUG is also true.
How do I turn off WordPress debug mode?
Set define( 'WP_DEBUG', false ); in wp-config.php, remove SCRIPT_DEBUG and SAVEQUERIES if you added them, and delete debug.log. You can confirm the values under Tools > Site Health > Info.
The bottom line#
WordPress debug mode is the fastest way to turn a blank page or critical error into a specific file and line number. On a live site, log errors with WP_DEBUG_LOG, hide them with WP_DEBUG_DISPLAY set to false, keep the log out of public reach, and switch everything off when you're done. Use Query Monitor when the site still loads, and recovery mode when it doesn't.
Find out what broke before your visitors do. Start monitoring your site free with MyKavo and install the free MyKavo WordPress plugin, no card needed.
Write for MyKavo
Know website monitoring, WordPress or SEO from real work? Pitch us a guide. You keep a byline with one link to your site. Read the guidelines
Get alerted when your site breaks. Free, no card.
Start free