How to Debug WordPress?

How to Debug Wordpress?


Debugging code is a part of any significant web development project that all users should understand in order to keep their websites up and running effectively. WordPress comes with a range of specific and valuable debugging options that keep the process as simple as possible, and use the same code across the core WordPress software, any plugins you may  have installed, and whichever themes you are running on your WordPress site. Knowing about debugging wordpress is important if you want to do anything related to PHP coding in wordpress, and you’ll want to do all you can in order to keep your newly coded site running as smoothly as possible at all times.

Below, you’ll find a brief introductory guide to wordpress debug mode and how to use it, breaking down the major functions and uses of debugging wordpress and giving you all the information you need to get started on debugging your wordpress site as quickly and easily as possible.

What is WordPress debug?

WordPress debug, or WP_DEBUG, is a PHP variable that you can use to activate debug mode on WordPress. It is deactivated by default, and should be left that way on live and active websites. You should only activate WP debug when your website has been put into maintenance mode, as it can cause problems if used on live versions of sites that users may be attempting to access.

This function is available as part of WordPress core, and has been since version 2.3.1. It has developed some more advanced functionality and extra features since then, but the core of the functionality has remained pretty much the same since it was initially introduced to WordPress.

This functionality is used for troubleshooting. You can use wp debug to identify issues with third party code, such as plugins and themes that you may have installed to wordpress. It allows much more effective troubleshooting than would be possible using only regular live wordpress site modes.

How to debug WordPress

To activate wordpress debug mode, you’re going to need to start by logging into cPanel or using SSH to access your WordPress account. Using your preferred method’s file navigation or command prompt, open the “wp-config.php” file in your text editor of choice, and add a line that reads “define(‘WP_DEBUG’, true);”.

Save your changes and close the text editor you have been using. Debug mode has now been activated. In order to generate an error log for debug mode, add another line that reads “define(‘WP_DEBUG_LOG’, true);”. This will create a file called “debug.log” in the same directory, which will record any errors found in debug mode and allow you to send debug information to others to help you with troubleshooting.

Once you’re finished with debug mode, be sure to disable the debugging by changing the “true” in both of the above lines of code to read “false” instead. Once you’ve done that, you’ll be back in normal operational mode for wordpress, and can go back to using it as normal.

WordPress error logging

If you’re having problems with the database of your WordPress site, then enabling wordpress error log functionality can be helpful. When you enable this, then the “$wpdb->queries” array saves information such as what the database query was, how long it took to run, and which function caused the query to be sent.

To enable database query error logging, add a line to the “wp-config.php” file that you used to activate debug mode. This line should read “define(‘SAVEQUERIES’, true);”.


There are a number of more advanced debug options for wordpress that you can use if needed, but the above are the most important functions that you will need to know in order to debug wordpress. With the code options above, you should be able to perform most debug actions needed to maintain your wordpress site in the best condition possible.

WordPress is far easier to debug than many other content management systems, and as long as you’ve got a basic grasp of simple PHP coding, activating, using, and then deactivating wordpress debug mode is a simple and straightforward process that should not take too much time or effort in order to get the results you need in order to keep your WordPress site and all of its third party plugins and themes in working order.