W
WordPress SOPKnowledge Base
Search
← All topics

WordPress Debug Logging

runnable

WordPress debug mode configuration in wp-config.php, reading debug.log via tail and grep, Query Monitor plugin for development, custom error logging to debug.log or custom log files, and common WordPress error patterns with causes.

debugloggingwp-configtroubleshootingquery-monitor
Agent trigger phrases: wordpress debug · wp_debug true · debug.log wordpress · wordpress error log · query monitor plugin · wordpress fatal error · wordpress error logging · wp-config debug settings

Debugging WordPress without logging is guessing. Enable debug logs for every development and troubleshooting session.

Enable Debug Mode (wp-config.php)

define('WP_DEBUG', true);           // Enable debug mode
define('WP_DEBUG_LOG', true);       // Write to wp-content/debug.log
define('WP_DEBUG_DISPLAY', false);  // Don't display errors on screen (safe for production)
define('SCRIPT_DEBUG', true);       // Load unminified scripts
define('SAVEQUERIES', false);       // Set true to log DB queries (performance hit)

Never set WP_DEBUG_DISPLAY = true on production. It exposes code paths to visitors.

Read the Debug Log

# Watch in real time
tail -f /var/www/html/wp-content/debug.log

# Filter for errors only
grep -i "fatal\|error\|warning" /var/www/html/wp-content/debug.log | tail -50

# Clear log (after resolving issues)
truncate -s 0 /var/www/html/wp-content/debug.log

# Shared hosting (if SSH unavailable): use File Manager in cPanel

Query Monitor Plugin (Development Only)

Install Query Monitor for detailed per-request diagnostics:

  • Database queries: count, slow queries, calling function
  • PHP errors and warnings (with file + line number)
  • Hook and filter execution order
  • HTTP API calls made during request
  • Conditional tags (is_single, is_archive, etc.)
  • Block editor: block types on page, render times

Disable on production — adds overhead.

Custom Error Logging

// Log to wp-content/debug.log
error_log('[MyPlugin] Lead saved: ' . $lead_id);
error_log('[MyPlugin] API response: ' . print_r($api_response, true));

// Log to custom file with timestamp
function my_log(string $message, string $context = 'general'): void {
    $log_file = WP_CONTENT_DIR . '/my-plugin.log';
    $line = '[' . date('Y-m-d H:i:s') . "] [{$context}] {$message}\n";
    error_log($line, 3, $log_file);
}

Common Error Patterns

| Error Message | Likely Cause | Fix | |---------------|-------------|-----| | Fatal: allowed memory exhausted | Memory limit too low | Increase WP_MEMORY_LIMIT to 256M | | Fatal: Call to undefined function | Plugin not loaded or typo | Check plugin active, check function name | | Warning: Cannot modify header | Output before wp_head fires | Remove stray echo/whitespace | | PHP Parse error: syntax error | Typo in PHP code | Check line number in log, find missing ; or } | | 500 error, empty debug.log | Apache/Nginx error | Check /var/log/apache2/error.log | | White screen of death | Fatal error with DISPLAY=false | Check debug.log immediately |

Server Error Log Locations

# Apache (Ubuntu/Debian)
/var/log/apache2/error.log

# Nginx
/var/log/nginx/error.log

# cPanel hosting
~/logs/error_log

# WPX Hosting: available via WPX control panel > Logs