How to Enable WP_DEBUG in WordPress for Better Troubleshooting

Keeping I.T. Simple > Blog > How to Enable WP_DEBUG in WordPress for Better Troubleshooting
WordPress Tips & Tricks

Introduction

Have you ever encountered a mysterious issue on your WordPress site? Understanding the root cause is key to a quick fix. This is where a powerful WordPress feature, WP_DEBUG comes in –  Enable WP_DEBUG in WordPress to help you identify issues in your site’s code.

Understanding WP_DEBUG

WP_DEBUG is a PHP constant that enables the debug mode in WordPress. Enable WP_DEBUG in WordPress to display PHP errors, notices, and warnings that would otherwise go unnoticed. This tool is invaluable for developers and site administrators for troubleshooting.

Accessing Your wp-config.php File

To enable WP_DEBUG, you’ll need to access your site’s wp-config.php file. This file is typically located in the root directory of your WordPress installation.

WordPress wp-config.php in root directory

Use an FTP client or your hosting provider’s file manager to access it.

Editing wp-config.php to Enable WP_DEBUG

In your wp-config.php file, look for the line that says /* That's all, stop editing! Happy blogging. */.

Enable WP_DEBUG in WordPress wp-config file

Just before this line, edit following code changing false to true:

define( 'WP_DEBUG', false );

This line of code enables the debug mode. Remember to save the file after editing.

Additional WP_DEBUG Options

For more advanced troubleshooting, you might also consider using WP_DEBUG_LOG to save errors to a debug.log file in your wp-content directory, or WP_DEBUG_DISPLAY to control whether errors are displayed onscreen or hidden.

Using WP_DEBUG_LOG

To use WP_DEBUG_LOG in WordPress for error logging, first ensure WP_DEBUG is enabled in your wp-config.php file. Then, add the line define('WP_DEBUG_LOG', true); just below the WP_DEBUG line.

define( 'WP_DEBUG', true );
define('WP_DEBUG_LOG', true);

This command instructs WordPress to save any errors to a debug.log file located in your wp-content directory.

Enable WP_DEBUG in WordPress - Debug.log file

This log file becomes an invaluable resource for tracking down and understanding the specific errors your site is encountering, without displaying them publicly on your site. It’s especially useful for ongoing development or diagnosing intermittent issues.

Using WP_DEBUG_DISPLAY

WP_DEBUG_DISPLAY controls the visibility of errors on your website’s front end. After enabling WP_DEBUG in your wp-config.php file, you can manage onscreen error display by adding define('WP_DEBUG_DISPLAY', false);.

define( 'WP_DEBUG', true );
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

Setting this to false will hide the errors from being displayed on your website, which is particularly important for a live site to maintain a professional appearance and user experience. Instead, the errors will be logged (if WP_DEBUG_LOG is set to true) without disrupting your site visitors. Remember, while WP_DEBUG_DISPLAY is useful for hiding errors, it doesn’t resolve them, so regular checks of your debug log are recommended.

Best Practices and Safety Measures

Always backup your wp-config.php file before making changes. Also, it’s best practice to use WP_DEBUG on a staging site rather than a live site to avoid displaying errors to your visitors. Don’t forget to turn off WP_DEBUG after resolving the issue.

Conclusion

Enabling WP_DEBUG is a straightforward yet powerful way to diagnose and resolve issues in WordPress. It’s an essential skill for anyone managing a WordPress site.

Encountering issues with WP_DEBUG or need help troubleshooting WordPress problems? Robert at Keeping IT Simple is here to assist you. I can help resolve any debugging  issues you may be experiencing. Contact me for professional WordPress support.

About the author