Debugging in WP

Code

First thing you have to remember forever – “don’t touch your WP code!” In most causes WP stops working because of people who tried to “upgrade” their PHP or JavaScript code poorly. And mistakes that are displayed in browser console not always show you a real problem, so it will be difficult to find the reason why it’s not working for people who is going to fix it.

In the case nobody didn’t touch unknown files, but you still have some problems with WP site, there’re a few ways to identify what’s wrong.

WP_DEBUG

Here is the most important and handy debug-feature, which is not recommended to use on real site, just for local use. This function is disabled by default (false) and to activate it you need to switch it to true in configuration file. This file wp-config.php you can find in the core directory of your WP project (if you see there just wp-config-sample.php you have to rename it).

define( 'WP_DEBUG', false ); replace to define( 'WP_DEBUG', true );

When you activate debug mode, you will see all PHP error messages, so they may be fixed. It’s much better to see them, than white screen of death or default messages, that is so annoying, isn’t it? Following this way, you will be able to see the answers on typical questions like “What’s happening?” and “What should I do?”. Show this errors to your site developer and he will help you to find the solution.

Wordpress-debug

Besides, program languages are evolving, so some functions and arguments are becoming deprecated and should be changed for correction in WP appearance. In this case, WP_Debug will show you these deprecated elements and their new analogues, so you will figure out if there is problem in a new theme or WP plugin.

WP_DEBUG_LOG

This function is connected to the previous one, it registers and saves all WP_Debug errors (including errors of AJAX requests). It can be very useful if you want to see the error list later. To activate it, write in wp-config.php file:

define( 'WP_DEBUG_LOG', true );

If any errors occurred, debug.log file with errors list will appear in wp-content folder.

WP_DEBUG_DISPLAY

You can choose the way to see WP errors. If you don’t want errors to be displayed immediately, but want to see them later in debug.log, you may write in wp-config.php such a string:

define( 'WP_DEBUG_DISPLAY', false );

This function works only when WP_DEBUG and WP_DEBUG_LOG is enabled.

And all these functions together:

// Turn debugging on
define('WP_DEBUG', true);

// Tell WordPress to log everything to /wp-content/debug.log
define('WP_DEBUG_LOG', true);

// Turn off the display of error messages on your site
define('WP_DEBUG_DISPLAY', false);

// For good measure, you can also add the follow code, which will hide errors from being
displayed on-screen
@ini_set('display_errors', 0);

You can use a very beneficial plugin called Debug Bar to see all your logs in it. But you’d better not experiment with it on the live sites.

Hope this article will be helpful for you in your challenges to figure out what is debugging in WordPress and how to use it. Nevertheless, after you read it, what actions did you do when you had some problems on your site? Whether your behavior changed or not?

2 thoughts on “Debugging in WP

Leave a Reply