Tech Guides

How to Enable Debug Mode in WordPress

Learn how to activate WordPress debug mode using WP_DEBUG and where to add the required code in the wp-config.php file.

WordPress developers working on themes or plugins may need to enable the WP_DEBUG feature to identify and fix errors during development. The built-in debugging system helps display PHP and WordPress-related issues that may not appear by default.

The WP_DEBUG constant is commonly used while developing or testing a WordPress theme or plugin. Since some PHP errors are hidden during normal operation, enabling debug mode is considered a recommended practice for development environments.

The following code can be used to activate WordPress debug mode and related logging features:

php
1 define(‘WP_DEBUG’, true); // Enable WordPress Debug Mode
2 if (WP_DEBUG) {
3     define(‘WP_DEBUG_LOG’, true); // Create ‘debug.log’ file inside the ‘wp-content’ folder
4     define(‘WP_DEBUG_DISPLAY’, true); // Display error messages on pages
5     @ini_set(‘display_errors’, 1); // Show PHP error messages
6 }
7 define(‘SCRIPT_DEBUG’,true); // Enable debug mode for CSS and JS files

This setup allows developers to display errors directly on the screen and save them into a debug.log file located inside the wp-content directory.

Where to Add the Debug Code

The debug configuration code should be added to the wp-config.php file. This file is located in the root directory of a WordPress installation and contains the main configuration settings for the website.