… Everything you need to know about enabling WordPress debug.

Is 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.

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 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.

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

Summary

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

Featured On

Inc Magazine Logo  

Sitepoint logo  

CSS Tricks logo   

webdesignerdepot logo   WPMU DEV logo   

and many more!

Where are we hosted?

This site is proudly powered by FAST VPS InMotion Servers and given an insane speed thanks to MaxCDN!

Web Hosting MaxCDN - Speed up your website

New! DIVI 3.1 WordPress Template + PageBuilder

You'll surely create a perfect website with Divi 3.1!

Get an exclusive 10% OFF for CollectiveRay visitors until

Divi 3

 

Monstroid2 (Updated!)

The best-selling template from TemplateMonster has been given an awesome upgrade!

We've got an exclusive 10% OFF for CollectiveRay visitors on Monstroid2 until - use Coupon Code: collectiveray

Monstroid2 Super Update

 

TemplateMonster Bundles

Awesome bundles for awesome websites. $1300 worth of products for $49 only!

We've got an exclusive 10% OFF for CollectiveRay visitors until - use Coupon Code: collectiveray

TemplateMonster Bundles

 

The Outstanding HungryJPEG Bundles

AWESOMENESS! Bundles of premium font + graphic packs at more than 96% OFF!  Get a bundle for just $9 - ONLY!

The Hungry JPEG Awesome font bundles

 

Advertise on CollectiveRay.com

CollectiveRay (formerly known as DART Creations) is interested in developing partnerships with mutual benefit. If you like the stuff we publish and would like to develop a relationship, we'd be happy to hear from you. Go on - drop us a line - we'd love to hear from you :-)

 

 

Disclosure: CollectiveRay is funded personally out of pure passion for helping people working with websites. We do however generate some income through recommendations of products. This means if you click on a link and purchase an item we link to, we will receive a small sum out of that sale. We usually partner with vendors to make your purchase cheaper than buying direct.

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

Follow us on Social

Follow us on Facebook   Follow us on Google+   Subscribe to our RSS Feed   Follow us on Twitter