A Guide On How To Use The Debug Mode In WordPress
You may not be aware of it but, WordPress has a Debug Mode feature which lets you obtain details easily when something is not working right with your website.Â
When you’re experiencing problems with your WP site and the problem just will not go away, enabling its debugging mode may be a good idea to help you assess where it’s coming from. Enabling the debug mode will make the errors visible on the pages where they are occurring.
Adding a constant to your wp-config.php file will enable the debug mode. Sounds daunting? Don’t worry, the steps that we have here are quite simple and easy to follow.
Before anything else, you need to add the code below to your wp-config.php file, which you can find at the root of your WordPress install:
1 2 3 |
if ( isset($_GET['debug']) && $_GET['debug'] == 'debug') define('WP_DEBUG', true); |
And then, as shown on the example below, you will also need to add a GET parameter to the URL of any page you want to debug:
1 2 |
https://www.b3multimedia.ie/?debug=debug |
Keep in mind though that the purpose of debugging is only for development, so once you’re finished troubleshooting your site, make sure it is disabled again.
So What Exactly Is A WordPress Debug Mode?
All projects come with a PHP code for debugging. However, WordPress has its own special debug system specifically designed to make the entire process more simple. Also, all codes across its themes, plugins, and core are standardized.
The platform has different debugging tools. Understanding some of them will help you become more productive when it comes to your coding, and also improve its overall inter-operativity and quality.
Using WP_Debug
WP-Debug is a vital debugging tool. It is a PHP boolean constant or a permanent global variable located in your WordPress install’s wp-config.php file. You can use it to trigger the debug mode throughout WP.
By default, it is considered to be false, and you can set it to true within the wp-config.php file on WordPress development copies:
1 2 3 |
define( 'WP_DEBUG', true ); define( 'WP_DEBUG', false ); |
In the above example, you will not see apostrophes besides true and false values. As mentioned, these are boolean values. Setting the constant to ‘false’ will not make it a boolean but a string instead, and will be interpreted as true because of the quotes.
Once it is set to true, you’ll begin showing PHP notices, which are more like helpful and useful messages for the developers rather than errors. You’ll also see generated debug WordPress messages, notably the usage of deprecated function visible on the pages of your website.
These deprecated functions are incorporated in a lot of WordPress releases which have been flagged to demise later on. Knowing if you’re working with a plugin or theme that’s utilizing a deprecated function is vital so that you will be able to find and use a replacement instead.
WP-Debug is a convenient method to troubleshoot issues when something is not going right in your website. Remember though that you should not use it if your site is live. It’s highly useful during the course of development but poses a great danger to a live site since any text within the PHP notifications can expose every detail of your paths, codes, and all other crucial info of your site to your visitors.
WP_Debug_Log and Logging Errors
WP_Debug_Log is another helpful tool that you can use in combination with the WP-Debug tool where you can save every error message in a debug.log file. This is a particularly useful feature if you need to review the notifications or notices at a later time.
Adding the code below to your wp-config.php file will turn the debug logging on:
1 2 |
define('WP_DEBUG_LOG', true); |
After you’ve added the code, you can find your debug.log file in your website’s /wp-content/ directory. To access the directory, go to your File Manager in the cPanel or through FTP and SSH.
To access via File Manager, log in to the cPanel, then go to Files > File Manager. Navigate your website’s root and locate the /wp-content/ folder and click it. The debug.log will be listed there if there are errors that occurred. Click that file, and then the Download or View button found on the menu at the top.
Clicking view will allow you to see the error messages in your browser. Simply download the file if you want to move it to a plugin or pass it along to a theme author.
WP_Debug_Display
WP_Debug_Display is the tool you need if you want to prevent error messages from being published on the pages of your website.
This constant is just as useful as the others we listed here. It gives you the control of whether debug messages are displayed within your website’s HTML. It is true by default and displays warnings and errors once generated. You can hide any errors by changing it to false.
To enable this feature, add the code below to your wp-config.php file:
1 2 |
define('WP_DEBUG_DISPLAY', false); |
Make Everything Work Together
You also have an option to use all of these constants together to enable debugging and log your site’s error messages while hiding notices by using the following code:
1 2 3 4 5 6 7 8 9 10 11 12 |
// 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 following code, which will hide errors from being displayed on-screen @ini_set('display_errors', 0); |
Again, make sure you don’t use the WP_Debug on your live site.
To ensure nothing will go wrong, simply copy and paste the codes we have here exactly as they are. A wrong character or an added space can have an effect on your entire website. We hope you find this guide helpful! Let us know once you’ve tried them by commenting below!
Maciej Ekstedt
Maciej is the founder and CEO of B3 Multimedia Solutions. He is a self-made web designer and marketing expert, and he loves his job so much that he barely leaves the office. He transforms creative ideas into effective strategies for his company and for his clients. Maciej is fascinated by the phenomenon of megalopolis. He notices patterns and details which make up the whole thing, and he uses these skills in his work.
Use coupon code SLIDER15Â at checkout!
0 Comments