Header Text - Enable WordPress Debug Mode & Fix Errors title=Hosted.com Tutorial - WordPress Debug Mode: How to Enable It & Fix Errors

WordPress Debug Mode is a built-in feature that helps you find and fix problems on your WordPress website. It’s like a detective tool for your site—it reveals hidden issues that might otherwise not be visible. These errors can come from plugins, themes, or even WordPress itself. Therefore, enabling Debug Mode lets you see these problems clearly, and fix them before they cause bigger issues.

When you turn on WordPress debugging, it shows error messages or logs them to a file. These messages tell you exactly what went wrong, helping you troubleshoot. For example, if a plugin is causing your site to load slowly or crash, Debug Mode will point to the problem so you can fix it fast. This is helpful when your site is acting up, but you don’t know why.

Here we cover everything about WordPress Debug Mode. We’ll show you how to enable it, explain the different debug options, and ways to fix the errors that pop up. By the end of this guide, you’ll be confident using Debug Mode to keep your website running smoothly!

KEY TAKEAWAYS

  1. WordPress Debug Mode helps you find and fix errors by showing hidden issues.
  2. You can enable Debug Mode by editing the wp-config.php file or using a plugin.
  3. WP_DEBUG shows errors, while WP_DEBUG_LOG saves them to a log file.
  4. Use WP_DEBUG_DISPLAY to control whether errors show publicly on your site.
  5. Plugins like WP Debugging and Query Monitor make enabling Debug Mode easy without editing code.
  6. Always disable Debug Mode on live sites to keep error messages private.
  7. You may enable SCRIPT_DEBUG and WPDB error reporting to access versions of JavaScript & CSS files that haven’t been minified and debug any database-related errors respectively.

What is WordPress Debug Mode?

As we mentioned, WordPress Debug Mode is a feature that enables detailed logging and displaying of PHP errors, warnings, and notices that occur within the WordPress environment. It is activated by defining certain constants in the WordPress configuration file (wp-config.php), such as WP_DEBUG.

This mode is essential for developers to identify and diagnose issues with themes, plugins, or core functionality. When you enable this mode, it helps uncover hidden problems like deprecated functions, fatal errors, or coding issues that might not be visible in normal operations.

Use WordPress debugging when troubleshooting errors on your WordPress site, such as when your website starts behaving unexpectedly or showing error messages. It’s also helpful when testing new plugins or themes to ensure they don’t conflict with your existing setup.

Furthermore, try WordPress Debug Mode primarily in development and staging environments, not on live sites. The error messages displayed in Debug Mode can expose sensitive information about your website that you wouldn’t want the public to see.

Enabling WordPress Debug Mode via Code

Enabling Debug Mode via code is an essential step in troubleshooting website issues. It will help you quickly identify and resolve PHP errors, plugin conflicts, or theme-related problems. Once activated, you can view WordPress display errors in real time making it easier for developers to track bugs. Let’s walk through the steps together.

Enable WP_DEBUG

The WP_DEBUG global variable is a built-in WordPress feature that helps you identify and troubleshoot issues within your website. It is an important tool for developers, highlighting problems with PHP code in different website components, including themes, plugins, and core files.

To enable the WordPress Debug Mode, you’ll need access to your website’s core files, specifically the wp-config.php file located in the root folder of your WordPress installation.

This can be done through an FTP client like FileZilla or your hosting provider’s File Manager. These tools will allow you to navigate the files and make the necessary changes to activate Debug Mode.

At Hosted.com, we let users access their website’s files directly from their hosting account to make this process easy. Here’s how you can do the same:

Login to your Hosted.com control panel.

WordPress Debug Mode - Login to Hosted.com Account

Once you’re in, go to Manage ServicesWordPress Hosting. Then, click Manage next to your desired domain name.

WordPress Debug Mode - Domain Name Settings

On the next screen click Login under Product Information to access the Hosted.com cPanel.

WordPress Debug Mode - Access cPanel

Now, go to Tools Files File Manager.

WordPress Debug Mode - Access File Manager

Next, navigate to your WordPress root folder, which is public_html. Select the wp-config.php file and click Edit to open this file in cPanel’s built-in editor.

WordPress Debug Mode - Edit wp-config.php File

You’ll be prompted to confirm your action because you will edit the original file. Click Edit to proceed further. However, before you update anything, we recommend you create a backup.

WordPress Debug Mode - Confirm Edit Operation

When the file is open, locate the following line of code:

define( 'WP_DEBUG', false );

If this code line is missing, you can manually add it after the $table_prefix = ‘wpl1_’; line. Then, change the value of the WP_DEBUG variable from false to true, which activates WordPress Debug Mode.

WordPress Debug Mode - Enable Debug Mode

Now, click Save Changes to save your file.

WordPress Debug Mode - Save File

After you’ve saved the file, WordPress will start showing error messages on the front end, helping you identify any problems with your website’s code. For example, if you have code issues in your active theme’s functions.php file, you’ll see the error when you try to access your website:

WordPress Debug Mode - Unexpected String in functions.php File

This is fine if the website is in the development phase and isn’t public. However, enabling Debug Mode on your live site can disclose some sensitive information to the world.

To avoid this, we recommend using the WP_DEBUG_DISPLAY variable. When you set WP_DEBUG_DISPLAY to false, it hides error messages from the front end of your site, which is useful for keeping the user experience intact.

You may also use the WP_DEBUG_LOG variable, which saves PHP errors to a debug.log file inside the wp-content folder, providing a log of issues that can be reviewed later.

WordPress Debug Mode - Enable Debug Mode and Log Errors in Log File

Remember, WordPress will log all the messages that will occur after you activate WP_DEBUG_LOG, which means you set this variable’s value to true. However, to document the previous issues, you must replicate them manually.

WordPress Debug Mode - debug.log File

Enable SCRIPT_DEBUG

WordPress generally uses minified JavaScript (JS) and CSS files by default. These are compressed versions of files that are faster to load, improving your site’s performance. However, these minified files may hide crucial error messages, making it difficult to identify issues when customizing your website’s code.

This is where SCRIPT_DEBUG comes in handy. By enabling SCRIPT_DEBUG, you and developers can access versions of these files that are not minified and provide more detailed error messages. This makes troubleshooting JavaScript and CSS issues much easier, especially if you’ve recently modified your site’s appearance or added custom code.

Here’s the step-by-step process to enable SCRIPT_DEBUG:

On the Hosted.com cPanel, navigate to Files File Manager. Then, open the wp-config.php file in edit mode (we’ve already covered how to open the wp-config.php file in cPanel’s built-in editor).

Now, find the following line:

define( 'SCRIPT_DEBUG', false );

If this line doesn’t exist, add it before the line, “That’s all, stop editing! Happy publishing”. Then, change the value from false to true so that it reads as follows:

define( 'SCRIPT_DEBUG', true );

After that, save the changes by clicking Save Changes in the file editor.

WordPress Debug Mode - Enable Script Debugging in WordPress

Important: After you’ve finished troubleshooting and fixing the issues, it’s important to disable SCRIPT_DEBUG. To do this, return the value in the wp-config.php file to false (define( ‘SCRIPT_DEBUG’, false );). This will ensure your site returns to using minified files, optimizing performance and reducing load times.

Connect with our expert WordPress Hosting support team for the help you need.
We’re committed to resolving your concerns and promoting your success!

Enable WPDB Error Reporting

To debug database-related issues in WordPress, you can enable WPDB error reporting. This feature helps reveal errors within your WordPress database, and easily troubleshoot problems, such as failed queries or corrupt data.

To activate WPDB error reporting, you must edit the class-wpdb.php file, which handles WordPress database interactions. Here’s how you can enable it:

First, access your website’s files. You do this with an FTP client and your hosting provider’s File Manager. Then, navigate to the wp-includes folder in your WordPress installation. Within this folder, you’ll find a file named class-wpdb.php. This file is responsible for managing database-related tasks in WordPress.

Now, open the class-wpdb.php file in the editor. To do so, select the file and click Edit.

WordPress Debug Mode - Open class-wpdb.php File in Editor

Inside the file, find the line that initializes the $show_errors variable. To show errors change the value of $show_errors from false to true. This tells WordPress to display any database errors directly on your site, making debugging easier. Lastly, click Save Changes to save your file.

WordPress Debug Mode - Enable WPDB Error Reporting

After saving the changes, any database-related errors will now be visible. This helps identify potential issues like failed database connections or query problems. Once you have debugged the errors, turn off error reporting to avoid exposing sensitive information.

Enable PHP Error Log

PHP’s built-in error_log() function helps identify issues related to PHP code by logging errors on the server. This feature is essential for troubleshooting errors in WordPress and other PHP applications within your hosting environment.

By enabling PHP error logging, developers can track and fix problems faster, as the logs provide information about the types of errors and when they occurred. However, some hosting providers disable PHP error logging due to security concerns, so it’s important to check if this feature is available on your server.

To enable PHP error logging manually, you need to edit the php.ini file, which is the main configuration file for PHP. In this file, you can adjust settings such as error logging and display errors.

Remember: Some web hosts may restrict access to the php.ini file for security reasons, meaning that error logging might not be available, or you may need to contact your hosting provider to enable it.

However, as a Hosted.com user, you must log in to your Hosted.com account. Then, go to Dashboard Manage ServicesWordPress Hosting. Click on the Manage button located next to your desired website address.

WordPress Debug Mode - Manage Domain Name Settings

Then, click Login under the Product Information section to access the control panel.

WordPress Debug Mode - Login cPanel

After that, go to Tools Software Select PHP Version.

WordPress Debug Mode - Select PHP Version

On the PHP Selector page, switch to the Options tab.

WordPress Debug Mode - PHP Options

Here, you need to change the PHP version first, because options are impossible for the native version.

WordPress Debug Mode - Change PHP Version

When you change the PHP version, you’ll see PHP options. Check the box for log_errors to enable PHP error logging. However, if you want to display the error messages on the front end, click display_errors (though it’s recommended to leave this unchecked for security purposes).

WordPress Debug Mode - Enable PHP Error Log

Once PHP error logging is enabled, you can access the log file to view error messages. To do this on Hosted.com, navigate to Files File Manager from the cPanel dashboard. Go to the WordPress installation’s root directory and locate the error_log file to view all PHP error logging.

WordPress Debug Mode - PHP Error Log File

Remember: Logs may sometimes be stored in a folder named logs or .log.  If you don’t see the folder, click Settings in the top-right corner and check the Show Hidden Files (dotfiles) option. Sometimes the PHP error log file is named php_error_log or similar, depending on your hosting setup.

Also, if you have configured a custom path in the php.ini file, the log might be stored in a custom directory you set during configuration.

It’s important to remember that you don’t have to enable WordPress Debug Mode to log PHP errors. We’ve seen some instances where users think enabling Debug Mode is required to log PHP errors. These two are separate features:

1. PHP error logging (log_errors) setting in PHP will log errors directly to a file on the server, typically error_log or a custom path in the php.ini file. This can run independently of WordPress and captures PHP-related issues at the server level.

2. WordPress Debug Mode (WP_DEBUG) is a specific feature of WordPress that helps developers identify issues related to WordPress themes, plugins, or the core code. When you enable this, it can also log errors into the debug.log file within the wp-content folder using the WP_DEBUG_LOG constant.

So, PHP error logging is ideal for monitoring errors at the server level across all PHP applications. However, WordPress Debug Mode is useful for WordPress-related issues and provides more information related to themes and plugins.

How to Enable Debug Mode Using a Plugin

The methods we covered previously are recommended for those with basic coding knowledge. However, if you’re uncomfortable editing code, you can use a plugin to debug WordPress. One popular option is the WP Debugging plugin. This plugin makes it easy to turn on WP_DEBUG without touching your site’s files.

Another great plugin is Query Monitor, which gives detailed information about PHP errors, database queries, scripts, and styles. This tool is perfect for advanced debugging.

We’ve already covered how to install and configure the WP Debugging and plugins to enable WordPress Debug Mode; you will find this information at: How to Use WP Debugging & Query Monitor Plugins WordPress Debugging

Using these plugins, you can enable Debug Mode with just a few clicks and gain better insights into any errors on your site. Once you’re done debugging, you must disable the Debug Mode to avoid security issues.  Here’s how to disable it: How to Disable WordPress Debug Mode

Best Practices for Debugging WordPress

When debugging your WordPress site, follow best practices to ensure a smooth and safe process. First, avoid displaying error messages on live sites, as these can reveal sensitive information to visitors. Instead, log errors to a file using WP_DEBUG_LOG so you can review them without showing them to the public.

For safer testing, use a staging environment—a copy of your site where you can troubleshoot without affecting your live site. If you must debug on your live site, activate maintenance mode to prevent visitors from accessing this while you fix issues. This way, you can handle problems without disrupting your user experience.

These best practices ensure a smoother debugging process while maintaining your WordPress site’s security, stability, and user experience.

Strip Banner Text - Choose Hosted.com for unbeatable WordPress Hosting & support. [Learn more] title=The Best WordPress Hosting & Support From Hosted.com

FAQs

What is WordPress Debug Mode? 

WordPress Debug Mode is a feature that shows hidden errors on your site to help troubleshoot problems.

How do I enable Debug Mode? 

You can enable it by adding define( ‘WP_DEBUG’, true ); in the wp-config.php file.

Can I use a plugin to enable Debug Mode? 

Yes, plugins like WP Debugging make it easy to enable Debug Mode without editing code.

Is it safe to use Debug Mode on a live site? 

It’s best to use Debug Mode in a staging environment, but if you must use it on a live site, ensure that errors are logged privately and not displayed publicly.

What is WP_DEBUG_LOG? 

It logs all errors to a file for easy review without showing them to visitors.

Can Debug Mode help with plugin issues? 

Yes, it can identify errors caused by plugins or themes, helping you troubleshoot conflicts.

What is SCRIPT_DEBUG? 

It loads CSS and JavaScript files that haven’t been minified to make debugging easier.

What types of errors can Debug Mode reveal?

It can show PHP errors, plugin/theme conflicts, and database issues.

Should I turn off Debug Mode after fixing errors?

Yes, disable Debug Mode to prevent error messages from showing.

Can Debug Mode slow down my site?

It may slightly affect performance, so it’s best to use this only when troubleshooting.

How To Disable Comments On WordPress: A Step-By-Step Guide

WordPress Malware Removal: Manual & Automatic Methods

How to Install WordPress Themes: A Beginner’s Guide

How To Configure WordPress Error Logs: Identify & Fix Issues

How to Export A WordPress Site: A Step-By-Step Guide