How to enable WordPress debugging for less frustration

… Everything you need to know about enabling WordPress debugging.

Is this has this ever happened to you, you know why you need WordPress debugging.

You go to try out the latest and greatest WordPress 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 WordPress debugging is an essential feature for coders and web designers.

 

 

WordPress debugging

Wouldn’t it be great if you could easily find out the errors when you’re working on code to develop a new WordPress 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 WordPress installation.

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

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

This is due to the fact that WordPress doesn’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, WordPress codex highly recommends programmers to enable WordPress debugging.

In fact, enabling WordPress debugging 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 WordPress version, 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 debugging on your WordPress installation…

How to Enable WordPress Debugging with WP_DEBUG

wp debugging

The most important PHP constant that can be used to enable debugging mode on your WordPress 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 WordPress debugging, 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 WordPress debugging.
wp config error

  • Be careful before making any change to your wp-config.php file because it is the most important file in your WordPress 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 WordPress site,
  • Make sure you don’t enable WordPress debugging on a live site.

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

How to Log WordPress Errors to a File with WP_DEBUG_LOG:

If you would like to review the WordPress error notices later, you’ll need to turn on ‘WordPress debug logging’ using WP_DEBUG_LOG. This essentially enables WordPress 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.

WP DEBUG LOG

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 WordPress themes and plugins errors will be tracked and saved in the debug.log file.

How to Turn off Displaying WordPress 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 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);

How to enable script debugging with SCRIPT_DEBUG  

wordpress script debugging

So far we’ve discussed the importance of WP_DEBUG mode and how to enable it on your WordPress 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 WordPress theme and plugins, SCRIPT_DEBUG shows you if there are any Javascript or CSS errors.

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

As you may know, WordPress 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 WordPress 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 );

Summary

So far we’ve looked at different WordPress debugging 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 WordPress 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

One more thing...

Do you have friends or a Facebook group who you think would find this useful? Share this with them and then let me know what they think.

Want to supercharge your website?

 
Our website loads FAST ... just 1.29 seconds. We're hosted on FAST InMotion VPS servers We want YOUR website to be fast too, so we've gotten you an exclusive deal - 47% OFF for DART Creations friends + FREE domain! Check it out NOW!