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.

  • Why cant you install your theme on a local instance and leave debug equal to true? Its not a good idea to leave debug true on a live site.
    – user9447
    Commented Nov 11, 2015 at 2:43
  • 1
    @Darth_Vader It's much easier for me to debug on the remote site right now. At a later time I might setup a local install. But as you confirmed, it's not a good idea to leave debug set to true on a live site. So I want to enable it briefly to inspect any errors and then turn it off quickly if I have to. Local installs are unfortunately different than remote. Commented Nov 11, 2015 at 2:47
  • 1
    @Howdy_McGee not quite the same question. they mention log files and different variables than I am asking about. Commented Nov 11, 2015 at 2:49
  • I wouldn't suggest doing this but if you do you should do a redirect before enabling debug
    – user9447
    Commented Nov 11, 2015 at 2:56
  • 2
    WP_DEBUG is defined as a constant, not as a variable, to check it you should do if ( WP_DEBUG ) (without the $ symbol). Apart from that, the linked question by @Howdy_McGee seems what you need to switch on/off debug programmatically.
    – cybmeta
    Commented Nov 24, 2015 at 9:44

1 Answer 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';
  • 1
    Wouldn't it be good to add if_logged_in so this wont be visible to someone who doesn't need to see it?
    – user9447
    Commented Nov 11, 2015 at 2:49
  • 1
    Well, I wouldn't run it on a live site at all. If I did, displaying it only for admins is a pretty good compromise.
    – s_ha_dum
    Commented Nov 11, 2015 at 2:51
  • Is WP_DEBUG defined by default? It's defined in my wp_config.php but I've modified it. Commented Nov 11, 2015 at 5:56
  • 1
    It's is defined in a file meant to be edited. I don't know that I'd trust it to be defined.
    – s_ha_dum
    Commented Nov 11, 2015 at 8:26
  • 4
    I'm using if ( WP_DEBUG ) { } and it works just fine...
    – dev_masta
    Commented Mar 30, 2016 at 23:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.