InfoPhilicWordPressDebugging in WordPress: Easy guide

Debugging in WordPress: Easy guide

Troubleshooting PHP code is a piece of any undertaking. For this, WordPress incorporates a few settings that you can use to help investigate the principle application, topics, your own particular custom code, and that’s only the tip of the iceberg.

Some of the settings are specifically designed to use by developers and should not be used on “live” sites. Those settings include specific debug systems designed to simplify the process as well as standardize code across the core, plugins, and themes.

You can use them in certain scenarios to help troubleshoot errors you may be experiencing with third-party code, such as plugins or themes.

In this guide, I will tell you about various debugging tools and how you could efficiently perform WordPress debug task. I’m sure, it will increase the overall quality and interoperability of your code.

To do so, you initially need to enable debugging mode in WordPress:

  • Log in to cPanel, or access your account using SFTP.
  • Using the cPanel File Manager or the SFTP, open the wp-config.php file in your preferred text editor.
  • Add the following line to the wp-config.php file:
define('WP_DEBUG', true); // Enable WP_DEBUG mode
  • Save your changes and exit the text editor. If you choose SFTP then make sure you upload the updated wp-config.php file. Debugging mode is now active.

Enabling WP-DEBUG will cause all PHP errors, warnings and notices to be shown. This is probably going to alter the default conduct of PHP which just shows deadly mistakes as well as demonstrates a white screen of death when blunders are come to.

Such instance even leads to error messages for things that don’t seem broken but do not follow proper data validation conventions inside PHP.

Don’t get panic. They are easy to fix once you identified the relevant code and the resultant code will be bugless and easier to maintain.

Empowering WP_DEBUG will likewise cause notices about deprecated functions and arguments inside WordPress that are being utilized on your site. These are capacities or capacity contentions that have not been expelled from the center code yet but rather are slated for cancellation soon.

Though, there are also additional settings available in WordPress that will help you in your debugging task. Here is the list of them:

  • WP_DEBUG_LOG
  • WP_DEBUG_DISPLAY
  • SCRIPT_DEBUG
  • SAVEQUERIES

Let me explain them in detail,

1. WP_DEBUG_LOG:

WP_DEBUG_LOG is a partner to WP_DEBUG that makes all mistakes additionally be spared to a debug.log log record inside the/wp-content/. This is valuable on the off chance that you need to audit all notification later or need to see created off-screen.

Include the following line of code in your wp-config.php file:

define( 'WP_DEBUG_LOG', true ); // Enable Debug logging to the /wp-content/debug.log file

This will enable you to write to /wp-content/debug.log using PHP’s built-in error_log() function, which can be useful for instance when debugging AJAX events.

2. WP_DEBUG_DISPLAY:

WP_DEBUG_DISPLAY is another option that controls whether troubleshoot messages are appeared inside the HTML pages or not. The default is ‘genuine’ which demonstrates blunders and notices as they are produced. Setting this to false will conceal all mistakes. This ought to be utilized as a part of conjunction with WP_DEBUG_LOG so mistakes can be surveyed later.

for this, you need to incorporate the following line of code to wp-config.php.

define( 'WP_DEBUG_DISPLAY', false ); // Disable display of errors and warnings

3. SCRIPT_DEBUG:

SCRIPT_DEBUG will force WordPress to use the “dev” versions of some core CSS and JavaScript files rather than the minified versions that are normally loaded. You should use it when you are testing modifications to any built-in .js or .css files.

Add this piece of code to the same file as above:

define( 'SCRIPT_DEBUG', true ); // Use dev versions of core JS and CSS files (only needed if you are modifying these core files)

4. SAVEQUERIES:

The SAVEQUERIES is used as the definition that saves the database inquiries to a cluster and that exhibit can be shown to help examine those queries. The consistent characterized as true cases that make each query to be saved, to what extent that query executes, and what function called it.

define( 'SAVEQUERIES', true );

The array is stored in the global $wpdb->queries.

This could impact on your site performance. Thus, ensure to turn this off when you aren’t debugging.

Hence, you are done. Now, stop editing.

You might also like my other article for Setting Up WordPress Error Logs using WP-Config.

In case, if you faced some issues during DEBUGGING, feel free to ask your question in the comment section below.

You'll also like:
Continue to the category
Amit Malewar
Amit Malewarhttps://www.infophilic.com/
Amit Malewar has been the tutorial writer since 2013. His passion for helping people in all aspects of technology flow through the expert coverage he provides. In addition to writing for InfoPhilic, Amit loves to read and try new things.

Comment Policy: Your words are your own, so be nice and helpful if you can. Please, only use your real name and limit the amount of links submitted in your comment. We accept clean XHTML in comments, but don't overdo it please.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

GET STARTED
DEALS

Kinsta Hosting

Highly optimized servers for lightning-fast sites. High-security environment hack-fix guarantee. WordPress support experts at your fingertips. GRAB THIS DEAL
spot_img