Debugging WordPress – How To Use WP_DEBUG On Production Site

WP_DEBUG is a constant variable which is used to debug WordPress website. As WordPress is built using PHP, this constant display all PHP errors, warning, notices. It is recommended to keep WP_DEBUG value ‘true’ while building a WordPress website. By keeping this constant ‘true’ it will helpful for developers to catch or resolved all types of errors. WordPress developers should make sure that all errors are handled before site go to live.

However, there may be a situation where we have to fix errors in production only. There are some reasons for it. It can be because of newly installed or updated plugin, theme updates, change in file permissions, etc.

While issues occur in production, normally it’s on high priority. We don’t have much time to move production site on a staging server and then fix the issue. A developer has to fix the issue on production server only. And again, the site should not break or display maintenance mode for live audiences also(Of course, here we are not talking about white death screen).

Restrict WP_DEBUG On For IP Only

If you have a static IP address, then to find out the error you can restrict WP_DEBUG On for your IP only. In this way, if WordPress has any error it will display for your IP only. Live audiences will not see any kind of error. By doing so, you can fix the error and once fixed remove the IP condition.

Make sure to take backup of the wp-config.php file before doing any edits.

wp-config.php

if ('YOUR_IP_ADDRESS' == $_SERVER['REMOTE_ADDR']) {
    define('WP_DEBUG', true);
} else {
    define('WP_DEBUG', false);   
}

Keep a note of you must have static IP address to perform this action. If your IP address is dynamic, then WordPress displays errors to all visitors. Because each time PHP control comes in the else condition.

Use Companions Of WP_DEBUG

WordPress provides 2 companions WP_DEBUG_LOG and WP_DEBUG_DISPLAY to WP_DEBUG. Using these 2 companions effectively, we can find out the errors and possibly fixes it. In this case, we don’t need to add any IP condition.

wp-config.php

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

If WP_DEBUG_LOG set to On it will create a debug.log file under wp-content/ directory. This error log file stores all types of PHP errors, warnings, notices, stack traces. Using this log file, the developer can get the idea about the error and can fix it. We have set WP_DEBUG_DISPLAY to off which will hide all errors on web pages. That means all errors will be logged in debug.log file and your users don’t see any errors on a website.

If you liked this article, then please subscribe to our YouTube Channel for video tutorials.

1 thought on “Debugging WordPress – How To Use WP_DEBUG On Production Site

Leave a Reply

Your email address will not be published. Required fields are marked *