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.
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 );
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.
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.
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 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.
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.
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.
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.
Frequently Asked Questions
How Do I Enable Debug Mode in WordPress?
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
WordPress is developed with the scripting language PHP and uses either MySQL or MariaDB as its open-source relational database management system. Behind the scenes, the WordPress database stores content such…
On WordPress websites, you can easily reset your user password in the admin area or using the “Lost your password?” link displayed on the WordPress login form. Unfortunately, there is…
Are you facing issues with your current hosting and want to move to a new web hosting? Does the process of moving your website to a new host look too…
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.