• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Dev Tips / Check WP_DEBUG

Check WP_DEBUG

Last updated on April 19, 2020 by Sal Ferrarello

Recently I was talking to another developer about how to detect WP_DEBUG being set on a WordPress installation.

Here is the code I use.

if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
    // WP_DEBUG is set to a truthy value (e.g. true).
}

WP_DEBUG

WP_DEBUG is a constant used in WordPress to put the site into “debug” mode. The idea here is when figuring out a problem (i.e. debugging), additional information is helpful.

Three Possible States of WP_DEBUG

While we are interested in whether WP_DEBUG is a truthy or a falsey value, there is a third possible state. WP_DEBUG can be undefined. This is why our conditional has two checks:

  1. Is WP_DEBUG defined? defined( 'WP_DEBUG' )
  2. If WP_DEBUG is defined, is it a truthy value
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Programming, Solution Tagged With: WordPress, WordPress Plugin

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in