WordPress debugging

… Everything you need to know about enabling WordPress debug.

If this has this ever happened to you, you know why you need WordPress debugging:

You go to try out the latest and greatest plugin and as soon as you activate. Boom!

Your website - Dead!

You want to uninstall the plugin, but you can’t because the backend is dead too.

Or you’re a WordPress developer coding a new plugin, but you can’t figure out why it’s not working the way you want it to. That's why debugging is an essential feature for coders and web designers.


Wouldn’t it be great if you could easily find out the errors when you’re working on code to develop a new theme or a plugin?

WordPress debugging is a cool feature that allows you to easily find the errors and deprecated functions during code execution on your WP installation.

It comes especially handy during the debug process especially if you tried implementing some experimental features on your themes or plugins.

By default, the WP configuration hides PHP notices while loading a page. If you want to perform debugging of  PHP and the WP API, you'll need to do some tweaks.

This is due to the fact that most websites don’t want to show PHP errors on a live site, which can be dangerous as the notices can reveal crucial details about your code, paths and other information to your site visitors, which can give hints to hackers to exploit the malicious codes to breach the security of your website.

Recommended Reading: 17 actions to prevent boost WordPress security

During the development phase, the WP codex highly recommends programmers to enable WordPress debugging.

In fact, enabling debug will help you in 2 ways.

  • PHP errors: It shows errors caused by any PHP functions
  • Deprecated functions: These are functions that might have used in previous versions of code, but have been recently marked as not to be used anymore. This will help you to find replacement function to use instead.

In this post, let’s take a look at various WordPress debugging constants and how to turn on error logging on your installation or website…

1. Enable WP Debugging with WP_DEBUG

wp debugging

The most important PHP constant that can be used to enable debugging mode on your site is WP_DEBUG.

By default, this PHP constant is set to false. It will look as follows in your wp-config.php file. 

define( 'WP_DEBUG', false );

In order to turn on logging, all you need to do is to set WP_DEBUG to true.

See the code below.

define( 'WP_DEBUG', true );

Below are a couple of things, you’ll need to keep in your mind before enabling.
wp config error

  • Be careful before making any change to your wp-config.php file because it is the most important file in your installation that can be used to configure database functionalities, enhance performance and improve securities. Making any tiny mistake can make your site inaccessible since wp-config.php file is so crucial to your site,
  • Make sure you don’t enable WordPress debugging on a live site.

Recommend Reading: How to backup WordPress natively or with a plugin

2. Log Errors to a File with WP_DEBUG_LOG

If you would like to review any error notices, you’ll need to turn on ‘WordPress debug logging’ using WP_DEBUG_LOG. This essentially enables the framework to write to a log file.

What this PHP constant does is it saves all error notices in a debug.log file located in the ‘wp-content’ directory, so you can review them whenever you want.

Please note that in order to make the WP_DEBUG_LOG work, it must be used in conjunction with WP_DEBUG constant.

Here is how to enable debug logging to debug.log file. Simply add the following code to your wp-config.php file.

define( 'WP_DEBUG_LOG', true);

Once it is set to true, all of your themes and plugins errors will be tracked and saved in the debug.log file.

3. Turn off Displaying Errors with WP_DEBUG_DISPLAY

displaying WP DEBUG

If you turned on WP_DEBUG_LOG in order to keep track of all the errors caused by your themes and plugins, chances are you may not want to display PHP notices on the site.

Maybe, you don’t want to get annoyed with errors while executing your code or you would fix the errors after some time.

Whatever it may be, you can easily turn off displaying WordPress errors using a constant WP_DEBUG_DISPLAY. It gives you control on whether debug messages are shown inside the HTML of your site.

By default, displaying WordPress debugging messages are set to ‘true’. You can turn it to ‘false’ if you want to hide the debugging messages.

All you need to do is to add the below line of code to your wp-config.php file.

define( 'WP_DEBUG_DISPLAY', false);

4. Enable script debugging with SCRIPT_DEBUG  

WP script debugging

So far we’ve discussed the importance of WP_DEBUG mode and how to enable it on your website installation.

Now let’s take a look at another important PHP constant, SCRIPT_DEBUG.

While enabling WP_DEBUG reveals any errors caused by PHP functions on your WP theme and plugins, SCRIPT_DEBUG shows you if there are any Javascript development or CSS errors.

In fact, while debugging if the SCRIPT_DEBUG constant is turned on, it forces WP to use the dev version of files instead of the minified version.

As you may know, WP loads minified versions of CSS and JS files in the live environment, which removes all unnecessary characters in those files in an effort to reduce the file size for faster page loading, which also results in saving bandwidth.

Recommend reading:17 actions to make WordPress faster

While loading minified files can be extremely helpful in terms of user experience and WordPress SEO, it can be a pain for development purposes especially when you’re finding and fixing bugs to make improvements.

By forcing the installation to load the dev version, you can easily figure out what scripts conflict in your core CSS and JS files using the browser tools console.

To turn on SCRIPT_DEBUG, add the following code to your wp-config.php file.

define( 'SCRIPT_DEBUG', true );


So far we’ve looked at different debug methods and how to enable and disable them in order to find errors.
to true if you enabled WP_DEBUG_LOG)
define( 'WP_DEBUG_DISPLAY', false);

To enable script debugging notices and to force WP to load dev file versions, add the below line of code. (By default, it is set to true if you enabled WP_DEBUG_LOG)
define( 'SCRIPT_DEBUG', true );

Have you ever turned on WordPress debugging? Share your thoughts with us in the comments section…

Download the list of 101 WordPress tricks every blogger should know

101 WordPress tricks

Click here to Download Now

Need help getting stuff done? Try these top-rated affordable gigs on Fiverr!

fiverr logo

Click here to find experts on fixing WordPress problems.

Click here to create a full WordPress website.

About the Author
Shahzad Saeed
Author: Shahzad SaeedWebsite: http://shahzadsaeed.com/
Shahzaad Saaed has been featured in a large number of authority websites, as a WordPress expert. He specializes in content marketing to help business grow their traffic.

One more thing... Did you know that people who share useful stuff like this post look AWESOME too? ;-)
Please leave a useful comment with your thoughts, then share this on your Facebook group(s) who would find this useful and let's reap the benefits together. Thank you for sharing and being nice!

Disclosure: This page may contain links to external sites for products which we love and wholeheartedly recommend. If you buy products we suggest, we may earn a referral fee. Such fees do not influence our recommendations and we do not accept payments for positive reviews.

Featured On

Inc Magazine Logo  

Sitepoint logo  

CSS Tricks logo   

webdesignerdepot logo   WPMU DEV logo   

and many more!



Get Started Now With ShutterstockShutterstock

Best Rated Caching Plugin

Make your website faster 

How to make your website FAST!

Step-by-step - free email course, how to make your website load in less than 1 second  

who are we?

CollectiveRay is run by David Attard - working in and around the web design niche for more than 12 years, we provide actionable tips for people who work with and on websites. We also run DronesBuy.net - a website for drone hobbyists.

David attard