WordPress is a popular and powerful platform for creating websites, blogs, and online stores. However, sometimes you may encounter errors or issues that prevent your site from working properly. In such cases, you may need to enable WordPress debug mode to find out what is causing the problem and how to fix it.

WordPress debug mode is a feature that displays PHP errors, warnings, and notices on your site. It also shows you if any functions or arguments are deprecated and need to be replaced. Debug mode can help you identify and resolve coding errors, conflicts, or compatibility issues with plugins, themes, or custom code.

In this tutorial, we will show you how to enable WordPress debug mode using two methods: editing the wp-config.php file or using a plugin. We will also explain how to disable debug mode when you are done troubleshooting.

Method 1: Editing the wp-config.php file

The wp-config.php file is one of the most important files in your WordPress installation. It contains the configuration settings for your site, such as the database name, username, password, and prefix. It also has a constant called WP_DEBUG that controls the debug mode.

By default, WP_DEBUG is set to false, which means debug mode is disabled. To enable it, you need to change its value to true. You can do this by following these steps:

  1. Access your WordPress site’s files using an FTP client or a file manager in your hosting control panel.
  2. Locate the wp-config.php file in the root directory of your site and open it for editing.
  3. Find the line that says /* That's all, stop editing! Happy blogging. */ and add the following code above it:
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
  1. Save the changes and refresh your site. You should now see PHP errors, warnings, and notices on your site.

If you want to log the errors to a file instead of displaying them on your site, you can add another constant called WP_DEBUG_LOG and set it to true. This will create a file called debug.log in the wp-content directory where you can view the errors.

// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

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

If you want to hide the errors from showing on your site but still log them to a file, you can add another constant called WP_DEBUG_DISPLAY and set it to false. You can also use the ini_set function to disable the display_errors directive in PHP.

// 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 
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

If you want to use the development versions of core JavaScript and CSS files instead of the minified versions, you can add another constant called SCRIPT_DEBUG and set it to true. This is useful if you are modifying these core files or testing patches.

// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

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

Method 2: Using a plugin

If you prefer not to edit the wp-config.php file manually, you can use a plugin to enable WordPress debug mode. One such plugin is WP Debugging, which adds several debugging tools and constants to your site with a few clicks.

To use this plugin, follow these steps:

  1. Install and activate the WP Debugging plugin from your WordPress dashboard.
  2. Go to Settings > WP Debugging and check the box next to Enable WP Debugging.
  3. Optionally, you can also check the boxes next to other debugging tools and constants that you want to enable, such as WP_DEBUG_LOG, WP_DEBUG_DISPLAY, SCRIPT_DEBUG, SAVEQUERIES, etc.
  4. Click on Save Changes and refresh your site. You should now see PHP errors, warnings, and notices on your site or in the debug.log file depending on your settings.

How to disable WordPress debug mode

When you are done troubleshooting your site, you should disable WordPress debug mode as soon as possible. Leaving debug mode enabled can expose sensitive information about your site to hackers or visitors. It can also affect your site’s performance and appearance.

To disable WordPress debug mode, you need to reverse the steps that you followed to enable it.

  • If you edited the wp-config.php file, you need to change the values of WP_DEBUG and other constants from true to false or remove them altogether.
  • If you used a plugin like WP Debugging, you need to uncheck the box next to Enable WP Debugging and save the changes.

After disabling WordPress debug mode, make sure that your site is working correctly and that there are no errors or issues.

Conclusion

WordPress debug mode is a handy feature that can help you find and fix errors or issues on your site. It can also help you improve the quality and compatibility of your code. However, you should only use debug mode when you need to troubleshoot your site and disable it when you are done.

In this tutorial, we showed you how to enable WordPress debug mode using two methods: editing the wp-config.php file or using a plugin. We also explained how to disable debug mode and why it is important to do so.

We hope this tutorial was helpful and informative. If you have any questions or feedback, please let us know in the comments below. Thank you for reading!

Categorized in: