Debug Mode in WordPress

While your WordPress site is running, you will encounter some problems from time to time. Although you may solve these problems at some point, delaying them may cost you complaints or loss of site visitors.

So, how can you solve these problems as quickly as possible and ensure that your site remains in perfect condition? In fact, WordPress offers you a helpful feature that enables you to troubleshoot the causes of these problems, which is the Debug Mode feature. 

Activating this feature on your site will show you the error message in detail and explain to you why it occurred. This will make it easier for you to locate the error, and thus find a solution to it faster. 

In this article, we will explain to you how to activate Debug Mode on your WordPress site, and we will also show you how to use it in the best way on your site.

What is Debug Mode in WordPress?

By default, the Debug Mode feature is disabled on WordPress sites. Once you activate this mode, you will be able to directly view and troubleshoot the errors your site is facing. You will also be able to record all notifications about problems that appear in a special file called Debug.log.

After this feature displays all the errors on your site, you will be able to solve them yourself if you have the necessary programming skills. Or you can show it to the developer behind the site to help him find the source of the problem and learn more details about it. 

 


Activate the Debug Mode feature in WordPress

Follow these steps to activate debugging mode on your WordPress site:

1. Locate the wp-config.php file

The WP-config file contains all the settings and features of your WordPress site, and you must have access to it to enable this mode.

  • You can access this file by logging in to your hosting control panel ( cPanel ), then choosing File Manager, then going to the root folder of the WordPress installation to find the wp-config.php file directly inside it.
  • You can also access the file through the File Transfer Protocol ( FTP ) by downloading a program that allows communication with the document via the FTP protocol, such as  FileZilla . After downloading the program and logging into it, you will find the wp-config.php file directly in the (Public_html) folder. 

2. Edit the wp-config.php file

After you access the wp-config.php file in one of the previous ways, you must modify the code of this important file that contains the configuration settings for your site. Open the file in edit mode by right-clicking on it and selecting Edit. 

In order to activate the Debug Mode feature, you must find the following line of code within the file.

(‘WP_DEBUG’,false);

3. Add debug code

Once you have selected the previous command, delete it and replace it with the following code:

// 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 );

The first command in the previous code activates the Debug Mode feature on your site by giving the programming constant WP_DEBUG the value true.

The second command activates the feature of writing all errors, notifications, and warnings to the site’s log file debug.log by giving the WP_DEBUG_LOG programming constant the value true.

As for the last two commands, they disable the features of displaying errors on the front page of the site so that they do not appear in front of visitors, in order to protect the security of your site and not display sensitive information that may be exploited by hackers.  

Note: Each of the properties (WP_DEBUG, WP_DEBUG_LOG, and WP_DEBUG_DISPLAY) are public programming constants in the PHP language. They are activated by giving them the value true and deactivated by giving them the logical value false. Note that the logical values ​​are written without upper quotation marks “” so that they are not treated as strings. Textual.

4. View error log later

After you apply the previous commands and make sure that the error correction mode is activated correctly on your site, you can find the special log file that saves all the error messages and problems found on your site and find out the reasons for their occurrence. As we mentioned previously, it is the file wp-content/debug.log (it may be in another path if you changed the default save path).

Debug.log file in WordPress

When you activate the Debug Mode and set the value of WP_DEBUG_LOG to true as described above, all errors and problems that occur on the site will be saved in the debug.log file. This file is located in the wp-content directory by default. You can also save it to another custom path of your choice on the server.


Important additional points about Debug Mode

After learning about the error correction mode on a WordPress website and its basic features, it is important to learn about some important additional features and points associated with this mode.

1. WP_DEBUG_DISPLAY error log display feature

The primary purpose of this feature is to enable the feature of displaying problems and error messages directly on HTML pages, meaning that they will appear on the front pages of the site and in front of all visitors to the site. 

Therefore, you must be careful if you activate this feature on the Live website. Because if you do this, this may expose you and your site to the risk of sensitive information leaking and it may be exploited by hackers.

So, if you want to activate this feature, first make sure that the site is not live, then activate it by writing the following command in the wp-config-php file:

(‘WP_DEBUG_DISPLAY’, true );

2. SCRIPT_DEBUG property

This feature is useful if you are testing some changes in your javascript js files. Or css files on the site. When this feature is activated with the Debug Mode feature, WordPress uses the Dev versions of these files instead of the compressed ( Minified ) versions that are usually downloaded, which makes it easier for you to discover and correct errors in them. 

By default, this feature is not enabled. To activate it manually, you can add the following command to the file wp – config – php

(‘SCRIPT_DEBUG’, true );

3. Change the path of the error log file

As mentioned in the previous commands, when we activate the Debug Mode feature, we immediately afterwards activate the WP_DEBUG_LOG log feature to save all error messages and problems in the debug.log file.

You can use the following code to change the path of the file where error reports are saved to protect it from hackers, 

(‘WP_DEBUG_LOG’, ‘/path/outside/of/webserver/root/debug.log);

4. Make sure to disable Debug Mode when finished

The Debug Mode feature is certainly of great benefit, as it helps you identify and fix errors and problems on your site. But you should beware that this feature may be able to show text from your PHP code to site visitors if you do not set it up correctly.

So you should always remember to disable it after you finish fixing the bugs, and before the site goes live.

5. Activate debug mode using an extension

If you do not want to activate the Debug Mode feature manually through code, or you do not have access to the wp-config.php file (through the cpanel or FTP hosting control panel), do not worry, as you can still activate it from within the WordPress control panel The same using plugins. 

WordPress provides several plugins to control debugging mode, such as WP Debugging, which performs this task automatically. 

 To install the WP Debugging plugin on your site, log in to the WordPress control panel, then go to the Plugins section at the bottom of the control panel, and choose the Add new command .

The add-on installation window will appear. Type in the search box the name of the add-on ( WP Debugging ) and after finding the required add-on, click on the install now button as shown in the following image.

After the installation is complete, then activate the add-on on your site. You can find more information about installing plugins in WordPress

This add-on works immediately after activation, as upon activation it automatically sets the value true  for each of the following programming constants

  • WP_DEBUG : This option is enabled by default to activate debugging mode on the site. 
  • WP_DEBUG_LOG : Logs error messages to the debug.log file.
  •  SCRIPT_DEBUG : To force WordPress to use upgraded versions of Javascript and CSS files instead of minified versions.  
  •  SAVEQUERIES to log database queries and help you track and correct errors. 

When you deactivate the extension, all of these variables will automatically be set again to the default value of false  to deactivate it. 

You can also control more plugin settings by going to the Tools tab in the WordPress control panel, then choosing WP Debugging. The plugin settings page will appear as shown in the following image.

Through this window, you can activate some additional features by selecting the available checkboxes, which are:  

  • Set WP_DEBUG to true: This option is enabled by default when installing the plugin to enable debugging mode. 
  • Set WP_DEBUG_DISPLAY to false, default is true: By activating this option, you can prevent the feature of displaying messages to site visitors. 
  • Set WP_DISABLE_FATAL_ERROR_HANDLER to true : You can activate this option to enable  the site’s fatal error handling feature .

After activating the options you want, click the Save changes button to save the changes you made to your site. 

Note : We advise you to deactivate this add-on as soon as you finish fixing the site’s problems, in order to deactivate the error correction mode, which can be exploited by hackers to access important and sensitive data on your site. 

Thus, we learned about Debug Mode, which helps you identify and fix errors on your WordPress site. We explained two ways to activate it on the site, either manually by writing the necessary code in the wp-config.php file, or through the WordPress plugin (WP Debugging).

Finally, we remind you once again of the need to be careful when dealing with this situation on live sites, as this may affect the performance of the site first, and expose you to the risk of sensitive information leaking second. Therefore, it is necessary that you cancel it after you finish correcting your site errors. 

Avatar photo
I am a young man who has been working in WordPress and e-marketing for 10 years. I would like to share my experience with you so that we can become professional in WordPress I will be happy to share the experience with you.