How to Enable & Disable Debugging in WordPress

Bulletproof Backups for Your WordPress Website

Fortify your business continuity with foolproof WordPress backups. No data loss, no downtime — just secure, seamless operation.

Debugging is the process of locating, understanding and resolving errors in your code. It’s something that all website owners have to tackle to ensure their websites run efficiently.

WordPress websites are powered by core WordPress PHP files, plugins and themes. PHP errors are unlikely to be caused by core WordPress files unless you modify the files or use an incompatible version of PHP, but you will encounter errors if installed plugins and themes are not working in harmony with WordPress.

When problems do arise, it is up to you to isolate the errors and remove them. Thankfully, this process is greatly simplified by the debugging features that are available to WordPress users.

In this article, I would like to show you how to enable and disable WordPress debug features such as WP_DEBUG mode to help you resolve major errors on your website.

What is WordPress Debug?

WP_DEBUG is a PHP constant in WordPress that can be used to enable “Debug” mode throughout your website. It’s disabled by default, but can be enabled by adding one simple line to the wp-config.php configuration file.

Normally, PHP only shows fatal PHP errors on your website, however, Debug mode can be used to show and log all PHP errors, notices and warnings. This can include messages about recommended PHP conventions being broken.

Debug mode also shows all deprecated functions and arguments that are being used within your WordPress website. Additional PHP constants such as SCRIPT_DEBUG and SAVEQUERIES can be used to analyse website problems too.

To put it simply, WordPress debug mode lets you see the error messages that are normally hidden. It’s an essential feature for troubleshooting problems on your website.

How to Enable WordPress Debug Mode

WordPress debugging mode can be enabled by either editing the wp-config.php file or installing a debug plugin. It is generally advised to perform debugging in a development area such as a staging website, not on a live website.

The wp-config.php file can be easily modified using File Transfer Protocol (FTP) clients such as FileZilla or the file manager that your hosting company provides.

Website File Manager
WP-Config.php can be modified directly using a file manager.

Before you make any changes to wp-config.php, I encourage you to create a backup of the existing file. This allows you to easily revert changes, if necessary.

1. How to Enable Debug Mode in WordPress Manually

WordPress debug features are detailed on WordPress.org in the article “Debugging in WordPress“. The article provides example code which:

  • Logs all errors, notices and warnings, to a file called debug.log within the wp-content directory
  • Hides the errors so they do not interrupt page generation

This is the example code they provide:

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

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

WordPress notes that the above code needs to be inserted in wp-config.php before the stop editing line.

/* That's all, stop editing! Happy publishing. */

Let’s break down the debugging code that WordPress provides and talk about the other debug constants that are available to you.

As noted previously, the PHP constant WP_DEBUG can be used to enable debugging across your website. By default, this constant is initially set as false in wp-config.php.

define( 'WP_DEBUG', false );

So to enable debugging, all you have to do is set WP_DEBUG to true.

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

WP_DEBUG_LOG can be used alongside WP_DEBUG to save all errors to a debug.log log file. It does this using PHP’s error_log() function.

// Enable Debug logging
define( 'WP_DEBUG_LOG', true );

The default location of the debug.log file is wp-content/debug.log, but you can change this location if you like.

// Save debug log file to a custom directory called my-error-logs
define( 'WP_DEBUG_LOG', '/my-error-logs/wp-errors.log' );

WP_DEBUG_DISPLAY controls whether debug messages are displayed in HTML messages. In other words, whether they are displayed on your WordPress posts and pages.

By default, WP_DEBUG_DISPLAY is set to true so that all debug messages are displayed. A practical alternative is to set WP_DEBUG_DISPLAY to false and log all messages to debug.log instead.

// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );

If you are analysing CSS or Javascript code, you can use the constant SCRIPT_DEBUG so that the developer version of .css and .js files are used instead of minified files.

// Use the use the developer versions of core CSS and JavaScript files
define( 'SCRIPT_DEBUG', true );

SAVEQUERIES allows you to save all database queries to an array. When SAVEQUERIES is set to true, the $wpdb global object stores all database queries in $wpdb->queries with details of how long each query took to execute and which function called it.

Kevin Dees wrote a good explanation of how this can be utilised in his article “How to Display and Debug All Database Queries Made by WordPress“.

// Save all database queries to an array
define( 'SAVEQUERIES', true );

The example code that WordPress.org provides is a great starting point for debugging. I also recommend checking out the wp-config.php generator tool from GenerateWP. All you have to do is select what type of debugging you want and the tool will create the correct wp-config.php for you.

The wp-config.php Generator Tool
The wp-config.php generator tool.

As you can see, you only have to make a few small edits to wp-config.php in order to configure debugging on a WordPress website. Be sure to reference “Debugging in WordPress” for more information on the PHP constants that are available to you for debugging.

2. How to Turn on WordPress Debug Mode Using a Plugin

A good alternative to editing wp-config.php directly is to use one of the many debugging plugins that are available in the official WordPress plugin directory.

One such plugin is Debug. The plugin lets you overwrite your wp-config.php file by simply selecting which debug settings you want to enable. It even has the option to let you download your existing wp-config.php file as a backup. WP Debugging offers similar functionality, adding debugging to your wp-config.php file upon activation and removing those edits upon deactivation.

Debug Settings
Debug is incredibly easy to use.
WP Debugging
WP Debugging will overwrite your wp-config.php file.

WP Debug Log – Config Tool is another debug tool to consider. Like Debug and WP Debugging, it can be used to enable debugging from the WordPress admin area.

One of the great things about this plugin is that it lets you view PHP errors directly from the plugin settings page. There is an option to email new logs too.

WP Debug Log – Config Tool
The plugin simplifies the process of debugging.
WP Debug Log
WP Debug Log helps you see errors and warnings within the WordPress admin area.

WP_DEBUG is the main method of debugging PHP errors on a WordPress website, though the official WordPress plugin directory is home to many debug and analysis plugins which will help you troubleshoot your website.

If WP_DEBUG and SAVEQUERIES are enabled in wp-config.php, you can use Debug Bar to add a menu to the WordPress admin bar that shows queries, object cache and other useful information. Plugins such as Debug Bar Actions and Filters Addon can enhance Debug Bar to show additional information.

Debug Bar
Debug Bar can be accessed from the WordPress admin bar.

Another plugin that utilises the WordPress admin bar is Debug This. It generates an analysis of every aspect of your website, showing the queries, templates and files that have built pages. Query Monitor is a fantastic solution that I also recommend. It helps you debug database queries, PHP errors, hooks and actions, block editor blocks, enqueued scripts and stylesheets, HTTP API calls and more.

WP Crontrol and Advanced Cron Manager – debug & control are incredibly helpful when working with the WP-Cron system and User Switching can help when checking user permissions. It can also be worthwhile scanning your website using Health Check & Troubleshooting to pinpoint any potential issues with your website.

Debug This
Debug This is a fantastic analysis tool.
Query Monitor
Query Monitor gives you a better understanding of what is happening on your website.

As you can see, there’s a great selection of debugging and analysis tools available to WordPress users. I encourage you to try them out to see if they complement your debug process.

How to Disable WordPress Debug Mode

WordPress debugging can be switched off at any time. Doing so will stop error messages from being displayed and logged.

1. How to Manually Disable WordPress Debugging

If you enabled debugging by editing your website’s wp-config.php file, all you have to do is replace the debug code you added to the wp-config.php file and replace it with the original WP_DEBUG entry.

define( 'WP_DEBUG', false );

Once your wp-config.php has been updated, debug mode will be disabled.

2. How to Disable a WordPress Debug Mode Using a Plugin

The WP_DEBUG WordPress plugins that I tested can all be disabled by deactivating the plugin from the WordPress plugins page.

With other debug and analysis tools, it is worthwhile checking the plugin settings page before deactivating. You may find options here to manually disable debugging, delete logs and fully uninstall the plugin so that it is removed from the WordPress database

What to Do If WordPress Debug Isn’t Working

The wp-config.php file is a vital configuration file that details database connection information, installation paths, memory settings and more. The file is easy to work with, but you do still need to proceed with caution when updating it.

So in addition to performing all debugging on a test website or staging area, I recommend taking a backup of wp-config.php before you make any modifications to the wp-config.php file. In the event of WP_DEBUG not working correctly or your website crashing, you can revert back to a working version of wp-config.php and reapply the WordPress debug settings.

Final Thoughts

WordPress users follow many practices to ensure their websites operate effectively and remain online 24 hours a day. This includes using staging areas for updates and customisations, performing regular website backups, optimising speed and implementing WordPress security plugins to ensure their website is protected.

Debugging is another part of website maintenance that you should be comfortable with. WP_DEBUG and other WordPress debugging tools are quick to enable and will help you isolate and resolve website problems with ease. I encourage you to familiarise yourself with all the debugging tools on offer.

Good luck.

Kevin

Frequently Asked Questions

How Do I Enable Debug Mode in WordPress?

WordPress debug mode can be enabled by setting WP_DEBUG to true in the wp-config.php file. WordPress debug plugins such as Debug and WP Debugging can also be used to enable debugging.

Is it Better to Edit WP-Config.php Manually or Use a WordPress Debug Plugin?

It makes no difference whether you use edit wp-config.php manually or use a WordPress plugin. WordPress debug plugins simply overwrite the wp-config.php file for you.

Where Are Debug Error Messages Saved?

WP_DEBUG_LOG has to be enabled in wp-config.php in order for error messages to be saved. The default filename and location of this log is /wp-content/debug.log, but the file name and location can be amended.

How Do I Stop Showing Error Messages On My Website?

By default, enabling WP_DEBUG will start showing PHP error messages on your website. This can be useful if you are debugging WordPress in a staging area as it lets you see errors as you navigate your website.

If you prefer, you can stop showing these error messages by setting WP_DEBUG_DISPLAY to false.

How Do I Disable WordPress Debugging?

WordPress debugging is enabled by modifying the wp-config.php file. To disable debugging, all you have to do is revert the changes you made to wp-config.php, ensuring that WP_DEBUG is set to false.

You may also like


How to Limit Form Submissions with Droip in WordPress
How to Limit Form Submissions with Droip in WordPress

Forms are an indispensable part of any website because of their versatility, letting you collect information for various purposes! However, people with ill intentions often attempt to exploit these forms…

Manage Multiple WordPress Sites
How To Manage Multiple WordPress sites

Management tools help agencies become well-oiled machines. Each task is completed with the least amount of effort and highest rate of  accuracy.  For people managing multiple WordPress sites, the daily…

PHP 8.3 Support Added to Staging Feature
PHP 8.3 Support Added to Staging Feature

We’ve introduced PHP version 8.3 to our staging sites. Test out new features, code changes, and updates on the latest PHP version without affecting your live website. Update PHP confidently…

How do you update and backup your website?

Creating Backup and Updating website can be time consuming and error-prone. BlogVault will save you hours everyday while providing you complete peace of mind.

Updating Everything Manually?

But it’s too time consuming, complicated and stops you from achieving your full potential. You don’t want to put your business at risk with inefficient management.

Backup Your WordPress Site

Install the plugin on your website, let it sync and you’re done. Get automated, scheduled backups for your critical site data, and make sure your website never experiences downtime again.