How to check if debug is true and can I use it for my own code? [duplicate]

I’m needing to debug one of my themes and I want to be able to switch on a debug mode so I can output more information or switch off debug mode and not see any information.

I noticed there is a debug variable defined in wp_config.php. I can easily set this to true or false. Is it OK to use this variable for my own debugging purposes or should I create my own?

Also, how do I check for if debug is true? My PHP is a bit rusty. Is this correct:

define('WP_DEBUG', true);

if ($WP_DEBUG) {
   // do something
}

My question is different.

1
1

PHP constants don’t have the leading $. Strictly, this isn’t WordPress, but since there isn’t a Core is_debug() function that I am aware of, what you want is:

if (defined('WP_DEBUG') && true === WP_DEBUG) {
   echo 'd00d';
}

Leave a Comment