Bird
Raised Fist0
Wordpressframework~10 mins

Debugging with WP_DEBUG in Wordpress - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Debugging with WP_DEBUG
Enable WP_DEBUG in wp-config.php
↓
WordPress loads with debug mode ON
↓
PHP errors, warnings, notices are shown
↓
Developer reads error messages
↓
Fix code based on errors
↓
Disable WP_DEBUG after fixing
↓
Normal site runs
This flow shows how turning on WP_DEBUG helps catch errors by showing messages, guiding fixes, then turning it off for normal use.
Execution Sample
Wordpress
<?php
// In wp-config.php
define('WP_DEBUG', true);
// Trigger an undefined variable notice
echo $undefined_var;
?>
This code enables debugging and triggers a notice by using an undefined variable.
Execution Table
StepActionEvaluationResult
1Load wp-config.phpWP_DEBUG constant set to trueDebug mode enabled
2Run echo $undefined_var;Undefined variable usedPHP Notice displayed on screen
3Developer sees noticeReads message about undefined variableIdentifies bug location
4Fix code by defining variableVariable defined properlyNo notice on reload
5Set WP_DEBUG to falseDebug mode offSite runs normally without debug messages
💡 Debugging complete, WP_DEBUG disabled for production
Variable Tracker
VariableStartAfter Step 2After Step 4Final
$undefined_varundefinedundefined (notice shown)defined with valuedefined with value
Key Moments - 3 Insights
Why do I see error messages on my site after enabling WP_DEBUG?
When WP_DEBUG is true (see execution_table step 1), WordPress shows PHP errors and notices that normally stay hidden. This helps find bugs.
What happens if I leave WP_DEBUG enabled on a live site?
Leaving WP_DEBUG true on a live site shows errors to visitors, which can confuse users and expose sensitive info. Always disable after fixing bugs (see execution_table step 5).
Why does fixing the code stop the error messages?
Fixing the code (step 4) removes the cause of errors, so PHP no longer triggers notices or warnings, and debug messages disappear.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result at step 2?
APHP Notice displayed on screen
BDebug mode disabled
CVariable defined properly
DSite runs normally
💡 Hint
Check the 'Result' column for step 2 in the execution_table
At which step does the developer fix the code to stop errors?
AStep 1
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'Action' column describing fixing code in execution_table
If WP_DEBUG is set to false from the start, what changes in the execution?
APHP errors are still shown
BNo debug messages appear on screen
CSite crashes immediately
DUndefined variables become defined
💡 Hint
Refer to step 5 where WP_DEBUG is false and site runs normally
Concept Snapshot
WP_DEBUG is a WordPress constant to show PHP errors.
Set define('WP_DEBUG', true) in wp-config.php to enable.
Errors and notices appear on screen to help find bugs.
Fix code based on messages, then set WP_DEBUG false for live sites.
Never leave debug on in production to avoid exposing info.
Full Transcript
Debugging with WP_DEBUG means turning on a special setting in WordPress to see error messages. You do this by setting WP_DEBUG to true in the wp-config.php file. When enabled, WordPress shows PHP errors, warnings, and notices on the screen. This helps developers find and fix problems in their code. For example, using an undefined variable triggers a notice that appears on the page. After reading the message, the developer fixes the code to define the variable properly. Once fixed, the errors stop showing. Finally, WP_DEBUG is turned off to hide errors from visitors and keep the site clean. This process helps keep WordPress sites healthy and easier to maintain.

Practice

(1/5)
1. What is the main purpose of enabling WP_DEBUG in WordPress?
easy
A. To speed up the website loading time
B. To display and log PHP errors and warnings for debugging
C. To disable all plugins temporarily
D. To change the website theme automatically

Solution

  1. Step 1: Understand WP_DEBUG role

    WP_DEBUG is a constant in WordPress that helps developers see PHP errors and warnings.
  2. Step 2: Identify its main use

    It is used to display and log errors to help fix issues during development.
  3. Final Answer:

    To display and log PHP errors and warnings for debugging -> Option B
  4. Quick Check:

    WP_DEBUG shows errors = B [OK]
Hint: WP_DEBUG shows errors to help fix bugs [OK]
Common Mistakes:
  • Thinking WP_DEBUG speeds up the site
  • Confusing WP_DEBUG with plugin management
  • Assuming WP_DEBUG changes themes
2. Which line correctly enables debugging in the wp-config.php file?
easy
A. define('WP_DEBUG', false);
B. define(WP_DEBUG, true);
C. WP_DEBUG = true;
D. define('WP_DEBUG', true);

Solution

  1. Step 1: Check correct syntax for defining constants in PHP

    Constants are defined using define('NAME', value); with quotes around the name.
  2. Step 2: Identify correct value to enable debugging

    Setting WP_DEBUG to true enables debugging.
  3. Final Answer:

    define('WP_DEBUG', true); -> Option D
  4. Quick Check:

    Correct PHP constant syntax with true = C [OK]
Hint: Use define('WP_DEBUG', true); with quotes and semicolon [OK]
Common Mistakes:
  • Missing quotes around WP_DEBUG
  • Using assignment (=) instead of define()
  • Setting WP_DEBUG to false to enable debugging
3. Given this code in wp-config.php:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
What happens when a PHP error occurs?
medium
A. Error is logged to debug.log but not shown on the website
B. Error is neither shown nor logged
C. Error is shown on the website and logged to debug.log
D. Error is shown on the website but not logged

Solution

  1. Step 1: Analyze WP_DEBUG_DISPLAY setting

    WP_DEBUG_DISPLAY is set to false, so errors are not shown on the website.
  2. Step 2: Analyze WP_DEBUG_LOG setting

    WP_DEBUG_LOG is true, so errors are logged to the debug.log file.
  3. Final Answer:

    Error is logged to debug.log but not shown on the website -> Option A
  4. Quick Check:

    Display false + Log true = A [OK]
Hint: Display false hides errors; log true saves them [OK]
Common Mistakes:
  • Assuming errors show on site when WP_DEBUG_DISPLAY is false
  • Thinking errors are not logged if not displayed
  • Confusing WP_DEBUG_LOG with WP_DEBUG_DISPLAY
4. You enabled WP_DEBUG but no errors appear on your site or in the log file. What is the most likely cause?
medium
A. You forgot to set WP_DEBUG_LOG to true
B. You set WP_DEBUG_DISPLAY to true
C. You set WP_DEBUG to false
D. You did not save the wp-config.php file

Solution

  1. Step 1: Check WP_DEBUG status

    WP_DEBUG is enabled, so errors should appear or be logged.
  2. Step 2: Check if errors are logged

    If WP_DEBUG_LOG is not true, errors won't be saved to the log file.
  3. Final Answer:

    You forgot to set WP_DEBUG_LOG to true -> Option A
  4. Quick Check:

    Logging off means no error logs = A [OK]
Hint: Enable WP_DEBUG_LOG to save errors to file [OK]
Common Mistakes:
  • Thinking WP_DEBUG_DISPLAY controls logging
  • Assuming WP_DEBUG false but errors show
  • Not saving wp-config.php after changes
5. You want to debug a plugin error but avoid showing errors to visitors. Which settings in wp-config.php should you use?
hard
A. define('WP_DEBUG', false); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false);
B. define('WP_DEBUG', false); define('WP_DEBUG_LOG', false); define('WP_DEBUG_DISPLAY', true);
C. define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false);
D. define('WP_DEBUG', true); define('WP_DEBUG_LOG', false); define('WP_DEBUG_DISPLAY', true);

Solution

  1. Step 1: Enable debugging without showing errors

    Set WP_DEBUG to true to enable debugging and WP_DEBUG_DISPLAY to false to hide errors from visitors.
  2. Step 2: Enable logging to capture errors

    Set WP_DEBUG_LOG to true to save errors to the debug.log file for review.
  3. Final Answer:

    define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false); -> Option C
  4. Quick Check:

    Debug on + Log on + Display off = D [OK]
Hint: Show no errors but log them with WP_DEBUG_DISPLAY false [OK]
Common Mistakes:
  • Turning off WP_DEBUG disables all error reporting
  • Showing errors to visitors by setting WP_DEBUG_DISPLAY true
  • Not enabling WP_DEBUG_LOG so errors are lost
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard