Features Pricing Docs Blog Log In Get Started Free

Enabling WordPress Debug Mode

WordPress Debug Mode Configuration

Debug mode reveals PHP errors, notices, and warnings that WordPress normally hides. It is essential for troubleshooting but should never be enabled on production sites visible to visitors.

Debug Constants in wp-config.php

Add these constants before the line /* That's all, stop editing! */:

Constant Purpose Recommended Value
WP_DEBUG Master switch for debug mode true (dev) / false (prod)
WP_DEBUG_LOG Write errors to wp-content/debug.log true
WP_DEBUG_DISPLAY Show errors on screen false (log only, safer)
SCRIPT_DEBUG Use unminified CSS/JS core files true (only when debugging scripts)
SAVEQUERIES Log all database queries true (only when debugging queries)

Safe Debug Configuration

This configuration logs errors without showing them to visitors:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

Reading the Debug Log

# View latest errors
tail -100 /home/DOMAIN/public_html/wp-content/debug.log

# Search for specific errors
grep "Fatal" /home/DOMAIN/public_html/wp-content/debug.log

# Watch in real time
tail -f /home/DOMAIN/public_html/wp-content/debug.log

Debugging Database Queries

When SAVEQUERIES is true, all queries are stored in $wpdb->queries. Add this to your theme’s footer.php temporarily:

<?php
if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
    global $wpdb;
    echo '<!-- ' . count( $wpdb->queries ) . ' queries -->';
}
?>

Quick Enable/Disable via WP-CLI

# Enable debug
sudo wp config set WP_DEBUG true --raw --path=$WP --allow-root
sudo wp config set WP_DEBUG_LOG true --raw --path=$WP --allow-root

# Disable debug
sudo wp config set WP_DEBUG false --raw --path=$WP --allow-root

Security Warning

  • Never set WP_DEBUG_DISPLAY to true on a public site — it exposes file paths and system info
  • The debug.log file is publicly accessible by default at /wp-content/debug.log — block it in your OLS config
  • Disable SAVEQUERIES in production — it stores every query in memory
  • Remove debug constants when done troubleshooting