How to Enable and View Errors on a WordPress Site (WP_DEBUG)

When adding custom code such as PHP or JavaScript, you may need to identify errors in your code. Enabling WordPress debug mode will log any errors detected on your site. This is useful for troubleshooting issues or learning more about potential problems.

Step 1: Locate the wp-config.php File

By default, WordPress debug mode is disabled. To enable it:

  1. Access your site files via FTP or cPanel.

  2. Find the wp-config.php file in the root folder of your site.

Step 2: Edit the wp-config.php File

The wp-config.php file contains site-specific settings such as your database information and configurations from your hosting provider.

Step 3: Add Debug Code

Copy and paste the following snippet before the line:

// That's all, stop editing! Happy blogging.
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );

// Disable display of errors and warnings on the site
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

// Use dev versions of core JS and CSS files (only needed if modifying core files)
define( 'SCRIPT_DEBUG', true );

⚠️ This ensures debugging is enabled without displaying errors to site visitors. All logged data will be saved to /wp-content/debug.log.

Step 4: Replicate the Issue

This ensures that the problem gets recorded in the debug log.

Step 5: View the Debug Log

  1. Navigate back to your site files.

  2. Open /wp-content/debug.log.

The debug log will contain detailed information such as file paths and error messages, helping you track down the source of the issue.

Step 6: Disable Debug Mode (Optional)

Once you’ve resolved your issue, it’s a good idea to turn off debugging to prevent log files from growing indefinitely:

define( 'WP_DEBUG', false );

Accessing your website with debug mode disabled will no longer show errors on your site.