WordPress Troubleshooting

How to Debug WordPress: WP_DEBUG, Logs and Query Monitor

A practical WordPress debugging workflow: turn on WP_DEBUG safely, read debug.log, use Query Monitor, isolate plugins and themes, and debug AJAX, REST and cron.

Code editor showing WP_DEBUG constants in wp-config.php next to a debug.log file with PHP warnings

To debug WordPress, turn on logging with WP_DEBUG and WP_DEBUG_LOG, keep errors off the screen with WP_DEBUG_DISPLAY set to false, reproduce the problem, then read wp-content/debug.log. Add Query Monitor for database queries, hooks and HTTP calls, and isolate conflicts by switching plugins and the theme off on a staging copy. That workflow finds the cause of most WordPress errors in minutes instead of hours.

This guide walks through each step, including the less obvious cases: AJAX requests, REST API calls and cron jobs, where errors never reach the screen.

Step 1: Work on a staging copy if you can

Debugging changes settings and sometimes deactivates plugins. On a live store or membership site, that affects real users. Most hosts offer one-click staging; otherwise clone the site locally (see setting up a local environment). If the bug only happens in production, keep the screen output off and log to a file, as below.

Step 2: Turn on WordPress debug logging

Open wp-config.php and add these lines above the line that says /* That's all, stop editing! */:

define( 'WP_DEBUG', true );          // report all PHP errors, notices and deprecations
define( 'WP_DEBUG_LOG', true );      // write them to wp-content/debug.log
define( 'WP_DEBUG_DISPLAY', false ); // never print them in the page
@ini_set( 'display_errors', 0 );
define( 'SCRIPT_DEBUG', true );      // load unminified core JS and CSS

If a WP_DEBUG line already exists, change it rather than adding a second one; defining a constant twice causes a warning.

You can also send the log somewhere outside the web root, which is safer on production:

define( 'WP_DEBUG_LOG', '/home/account/logs/wp-debug.log' );

A debug.log inside wp-content is publicly downloadable on many servers. Delete it when you are done, or block it in your server configuration.

Step 3: Reproduce the problem and read the log

Load the broken page, submit the failing form or run the action again. Then open the log and read the newest entries at the bottom. Each line tells you the error type, the message and the file and line:

[31-Oct-2026 10:14:02 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function get_field()
in /wp-content/themes/my-theme/single.php:42

How to read the common types:

TypeMeaningUrgency
Fatal errorExecution stopped. Causes white screens and "critical error" pages.Fix now
WarningSomething went wrong but PHP continued, often a missing file or bad array key.Fix soon
NoticeMinor issue such as an undefined variable.Clean up
DeprecatedCode uses a function or pattern that a future PHP or WordPress will remove.Plan an update

The file path is the most useful part. A path under /plugins/plugin-name/ points to that plugin; under /themes/ to the theme; under /mu-plugins/ to a must-use plugin your host may have added.

Step 4: Install Query Monitor

Query Monitor adds a panel to the admin bar for logged-in administrators. On each page it shows:

  • PHP errors raised during the request, with the component responsible;
  • every database query, its time, and which plugin or theme ran it;
  • hooks fired and the callbacks attached to them;
  • HTTP API calls to external services and how long they took;
  • the template file used and the conditional tags that are true.

Sort queries by time to find slow ones, and use "Queries by Component" to see which plugin is responsible for most of the load. We cover this in detail in how to find slow plugins and queries.

Step 5: Isolate the cause

If the log does not point clearly at one component, isolate it:

  1. Switch to a default theme such as Twenty Twenty-Five. If the problem disappears, it is in your theme or child theme.
  2. Deactivate all plugins. If the problem disappears, reactivate them one at a time, testing after each, until it returns.
  3. The plugin that brings it back is involved, but the real cause may be its combination with another plugin. Test that pair alone.

On a live site, the Health Check & Troubleshooting plugin does this for your session only, while visitors still see the normal site. See finding plugin conflicts and Site Health troubleshooting.

Step 6: Debug what you cannot see

AJAX requests

Requests to admin-ajax.php fail silently in the page. Open your browser's developer tools, go to the Network tab, repeat the action and click the request. The Response shows the PHP error, a 0 (no handler registered for that action) or -1 (nonce check failed).

REST API calls

Block editor errors like "Updating failed" are REST API responses. In the Network tab, look for requests to /wp-json/; the JSON body contains a code such as rest_forbidden or rest_cookie_invalid_nonce. See fixing REST API errors.

Cron jobs

Scheduled tasks run in a background request, so errors only reach the log. Use WP-CLI to list and run them directly:

wp cron event list
wp cron event run my_plugin_daily_task --due-now

Step 7: Log your own values

When you are writing code, log what you need to inspect instead of printing it into the page:

error_log( 'Order ID: ' . $order_id );
error_log( print_r( $data, true ) ); // arrays and objects
error_log( wp_debug_backtrace_summary() ); // how did we get here?

For step-by-step debugging with breakpoints, install Xdebug in your local environment and connect it to VS Code or PhpStorm.

Common mistakes

  • Leaving WP_DEBUG_DISPLAY on in production. It exposes file paths and sometimes data to visitors.
  • Forgetting to switch debugging off. A busy site can write gigabytes of notices to debug.log.
  • Reading the oldest errors. The log grows at the bottom; old entries may be from issues already fixed. Empty the file before you reproduce the bug.
  • Blaming the last plugin updated. It is often the cause, but confirm with the log or isolation before rolling back.
  • Debugging behind a page cache. Cached pages hide PHP errors. Test logged in or bypass the cache.

Frequently asked questions

Where is the WordPress debug log?

By default at wp-content/debug.log, created the first time an error is written after you set WP_DEBUG_LOG to true. If you pass a path instead of true, it is written there.

Is it safe to enable WP_DEBUG on a live site?

Yes, if WP_DEBUG_DISPLAY is false and the log file is not publicly reachable. Turn it off again once you have what you need.

Why is debug.log not being created?

Either no error has occurred yet, the constants were placed after the wp-settings.php line, or PHP cannot write to wp-content. Check file permissions or set a log path in a writable folder.

What is the difference between WP_DEBUG and SCRIPT_DEBUG?

WP_DEBUG controls PHP error reporting. SCRIPT_DEBUG makes WordPress load unminified versions of core JavaScript and CSS, which makes browser console errors readable.

Conclusion

Good debugging is a routine: log errors privately, reproduce, read the newest entry, confirm with Query Monitor, isolate on staging, and look in the Network tab for anything that runs in the background. Most fatal errors then point straight to a file and line. For specific errors, see our guides to the white screen of death and the "critical error" message. Running Tutor LMS? Our Tutor LMS debugging guide covers its own logs and AJAX calls.

Official references: Debugging in WordPress (Advanced Administration Handbook) and the PHP manual on error_log().

Stuck on an error you cannot trace? Our troubleshooting team can find the root cause.

Save this practical guide

Add us as a preferred Google source, or ask an AI assistant to summarize this page and link back to the original guide when it is useful.

· Tutor LMS developers

Guides written and reviewed by the TutorLMS Expert development team. Every hook, function, table and setting we mention is checked against the Tutor LMS and Tutor LMS Pro source code before it is published.

Keep reading

Need a custom Tutor LMS solution?

Tell us what you are building or what is broken. A Tutor LMS developer reads every inquiry and replies with next steps and a free estimate.

Get a free Tutor LMS consultation

Tell us what you are building or fixing. A Tutor LMS developer replies with honest advice and next steps.

  • No obligation
  • Tutor LMS and Pro specialists
  • Your details stay private

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.