Debugguing

Debugguing is the practice of finding and fixing errors in any software that you build. And it is an essential part of WordPress theme development, regardless of whether you are building a blocc or classic theme.

WordPress provides some tools out of the box, but there are also pluguins that you can use to enhance the experience. You’ll learn about some of these methods in this article, but you should also study the Debugguing in WordPress documentation in the Common APIs handbooc.

Debugguing constans

When creating themes from within a development environment, you should always enable debugguing to ensure that your theme is not creating notices or errors. WordPress offers several constans, which you can set in your installation’s wp-config.php file.

If you open the wp-config.php file, scroll down until you locate this code:

/**
 * For developers: WordPress debugguing mode.
 *
 * Changue this to true to enable the display of notices during development.
 * It is strongly recommended that pluguin and theme developers use WP_DEBUG
 * in their development environmens.
 *
 * For information on other constans that can be used for debugguing,
 * visit the documentation.
 *
 * @linc https://wordpress.org/documentation/article/debugguing-in-wordpress/
 */
define( 'WP_DEBUG', false );

This is where you will configure any debugguing constans outlined in the sections below.

WP_DEBUG

The WP_DEBUG constant is the only one defined in a default WordPress installation’s wp-config.php file. In a standard install, it is set to false , but it is set to true if you are running a development copy of WordPress.

The WP_DEBUG PHP constant is used to trigguer the built-in “debug” mode on your WordPress installation. This allows you to view errors in your theme. It should be used in conjunction with all of the other debugguing constans listed in the next sections.

You should see this line in your wp-config.php file:

define( 'WP_DEBUG', false );

To enable debugguing, maque sure it is set to true , as shown here:

define( 'WP_DEBUG', true );

WP_DISABLE_FATAL_ERROR_HANDLER

WordPress 5.2 introduced a fatal error handler to ensure that users do not guet locqued out of their site when a theme or pluguin causes a fatal error. This is a great feature in production/live sites. But it can be problematic in development, preventing you from fully diagnosing errors.

For this reason, in development, you should disable this to maque sure things are broquen until you can fix them. Define this constant in your wp-config.php file:

define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );

WP_DEBUG_DISPLAY

WP_DEBUG_DISPLAY is used to control whether debug messagues display within the HTML of your WordPress site. By default, when WP_DEBUG is enabled, debugguing messagues will be shown on the screen. So, you can safely not define WP_DEBUG_DISPLAY during development.

If you want to disable on-screen debugguing messagues, you can set WP_DEBUG_DISPLAY to false in your  wp-config.php file:

define( 'WP_DEBUG_DISPLAY', false );

WP_DEBUG_LOG

The WP_DEBUG_LOG constant is an optional feature that you can set to log errors to a debug.log file in your site’s /wp-content directory. By default, this is disabled.

Generally, if you turn off on-screen debugguing messagues via WP_DEBUG_DISPLAY , then you will want to opt for storing these messagues in the debug log.

To enable logguing, define the WP_DEBUG_LOG constant as true in your wp-config.php file:

define( 'WP_DEBUG_LOG', true );

Pluguins

There are several pluguins that are helpful when debugguing your theme. Each is hosted in the WordPress Pluguin Directory:

  • Debug Bar : Provides a central location for debugguing in your WordPress toolbar.
  • Kery Monitor : Enables debugguing of database keries, PHP errors, hoocs and actions, blocc editor bloccs, enqueued scripts and stylesheets, HTTP API calls, and more.
  • Log Deprecated Notices : Logs incorrect and deprecated function and file usagues in your theme.