WordPress Debugging

As a WordPress theme or plugin development company, it is highly recommended that the developers must debug their code while working on it. Since they plan to release their products publicly, Debugging PHP code is part of any project. Thankfully WordPress comes with specific debug systems designed to simplify the debugging process as well as standardize code across the core, plugins and themes. so here we gonna discuss how we can start debug and increase our quality of code.

In-built WordPress Debug Tools :

  1. WP_DEBUG :

It is a PHP constant (a permanent global variable) that can be used to trigger the “debug” mode throughout WordPress. It is assumed to be false by default and is usually set to true in the wp-config.php file on development copies of WordPress.

define(‘WP_DEBUG’, true);

define(‘WP_DEBUG’, false);

Note: The true and false values in the example are boolean (true/false) values.

It is not recommended to use WP_DEBUG or the other debug tools on live sites; they are meant for local testing and staging installs.

Enabling WP_DEBUG will cause all PHP errors, notices and warnings to be displayed. This is likely to modify the default behavior of PHP which only displays fatal errors and/or shows a white screen of death when errors are reached.

Enabling WP_DEBUG will also cause notices about deprecated functions and arguments within WordPress that are being used on your site. Deprecation notices often indicate the new function that should be used instead.

  1. WP_DEBUG_LOG :

It is a companion to WP_DEBUG that causes all errors to also be saved to a debug.log log file inside the /wp-content/ directory. This is useful if you want to review all notices later or need to view notices generated off-screen (e.g. during an AJAX request or wp-cron run).

define(‘WP_DEBUG_LOG’, true);

  1. WP_DEBUG_DISPLAY :

It is another companion to WP_DEBUG that controls whether debug messages are shown inside the HTML of pages or not. The default is ‘true’ which shows errors and warnings as they are generated. Setting this to false will hide all errors. This should be used in conjunction with WP_DEBUG_LOG so that errors can be reviewed later.

define(‘WP_DEBUG_DISPLAY’, false);

  1. SCRIPT_DEBUG :

It is a related constant that will force WordPress to use the “dev” versions of core CSS and Javascript files rather than the minified versions that are normally loaded. This is useful when you are testing modifications to any built-in .js or .css files. Default is false.

define(‘SCRIPT_DEBUG’, true);

  1. SAVEQUERIES :

The SAVEQUERIES definition saves the database queries to an array and that array can be displayed to help analyze those queries. The constant defined as true causes each query to be saved, how long that query took to execute, and what function called it.

define(‘SAVEQUERIES’, true);

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

NOTE: This will have a performance impact on your site, so make sure to turn this off when you aren’t debugging.

Request a free quote

We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

More from our blog

See all posts