WordPress have a Debug Mode which allow you to easily get information when something goes wrong. To enable the debug mode, you have to add a constant to the wp-config.php file. But what about an easy way to switch on the debug mode, even without accessing wp-config.php?

The first thing to do is to add the following code to your wp-config.php file. This file is located at the root of your WordPress install.

if ( isset($_GET['debug']) && $_GET['debug'] == 'debug')
  define('WP_DEBUG', true);

Once done, simply add a GET parameter to the url of the page you’d like to debug, as shown below:

https://www.visualmodo.com/?debug=debug

What is Debug Mode?

Debugging PHP code is part of any project, but WordPress comes with specific debug systems designed to simplify the process as well as standardize code across the core, plugins and themes. This page describes the various debugging tools in WordPress and how to be more productive in your coding as well as increasing the overall quality and interoperativity of your code.

How enable/disable debug mode in WordPress
How enable/disable debug mode in WordPress

 

WP_DEBUG

WP_DEBUG 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 not surrounded by apostrophes (‘) because they are boolean (true/false) values. If you set constants to 'false', they will be interpreted as true because the quotes make it a string rather than a boolean.

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.

Debug WordPress with Sublime Text 2 and XDebug
Debug WordPress with Sublime Text 2 and XDebug

 

History

The WP_DEBUG option was added in WordPress Version 2.3.1.

Starting with WordPress version 2.3.2, database errors are printed only if WP_DEBUG is set to true. In earlier versions, database errors were always printed. (Database errors are handled by the wpdb class and are not affected by PHP’s error settings.)

Starting with WordPress version 2.5, setting WP_DEBUG to true also raises the error reporting level to E_ALL and activates warnings when deprecated functions or files are used; otherwise, WordPress sets the error reporting level to E_ALL ^ E_NOTICE ^ E_USER_NOTICE.

Share This Post