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

NOTE: 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 another 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.

ALSO READ

Subscribe to our newsletter

To be updated with all the latest news, offers and special announcements.

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

Start WordPress Blog: Ultimate Guide For Beginners

Here is our step by step guide for beginners to start a WordPress blog.

Top 6 Best WordPress Theme Frameworks

There are many websites themes which are created by using a framework. Likewise, WordPress Theme frameworks also becoming so popular. The framework allows you...

The Most Essential WordPress Plugins

Here, I have listed some excellent plugins which will surely add more features and new functionality to your WordPress blog.

Tips to Speed Up WordPress Performance

Here, I am sharing some tips to speed up WordPress performance. All you need to modify .htaccess file on your server and add some plugins.

The Ultimate Guide to Harden WordPress Security

Learn how to improve WordPress security. Here are some basic security concepts that will help you to harden WordPress security.

How to Setup CloudFlare Free SSL for WordPress Blog

Google has announced that they will count HTTPS as a ranking factor which means if you using HTTPS you will get a higher position...

DEALS

MonsterInsights

MonsterInsights is the best Google Analytics plugin for WordPress. Setup Google Analytics for WordPress with just a few clicks.

POPULAR NOW

Get almost 100% PageSpeed on Newspaper theme

The newspaper theme is the most popular premium theme for a self-hosted WordPress blog. The theme is developed by team tagDiv. You...

How to Remove jQuery Migrate in WordPress?

jQuery Migrate greatly simplifies the process of moving older jQuery code to a higher jQuery version by identifying deprecated features. It then restores deprecated...

How to setup CloudFlare CDN for WordPress blog

In today's world website speed is a crucial element to getting good ranks on the web. Website speed also aids for indexing your site...

How to Delete Multiple Images in WordPress Media Gallery

Hey, guys today one of my friends asked me a question, How can I delete Multiple Images in WordPress? I replied, "It's very simple." Yeah,...

WP Super Cache Plugin: Best Settings & Configuration Guide

A cache plugin serves static contents to the visitor which improves page load speed. There are so many cache plugins available in the...

How to Root Sony Xperia C (C2305)

Sony Xperia C is a one of the best smartphone available on the market. It comes with Cortex-A7 1.2 GHz quad-core processor along with...