Yoast: Building Page.ly Part4: Scalable and Fast Managed WordPress Hosting | Page.ly Blog http://t.co/ba32Hemn ReTweet Reply

Quick WP Tip: Simple WordPress debugging

After reading this post about the "WordPress white screen of death" I wanted to quickly share with you a quick hack I do in almost all WordPress installs I manage, that allows me to quickly switch on debug mode when needed.

In the file wp-config.php, usually found in your WordPress root, do the following:

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

Now I can open any page, and if something goes wrong there, like a white screen of death, I add ?debug=debug to its URL and see what's causing the trouble. Pretty easy huh? :)

Now it might be wise to change that second 'debug' to a key of your own choosing, so not everyone out there can open debug mode on your blog.


Category: WordPress
You can skip to the end and leave a response.

28 Responses to “Quick WP Tip: Simple WordPress debugging

Could you add that to functions.php?

Brilliant! Sure could have used this before. Thanks Yoast!

Thanks. And just in case anyone doesn't realise how to change that second 'debug' to a key of your own choosing, it's the third debug in the line of code above - "== 'debug')"

It's more secure to check if you are logged and have admin role. This way even if someone get your super secret key they won't see anything until they are admins on the blog.

global $current_user;
get_currentuserinfo();

if( isset( $_GET[ 'debug' ] ) && $_GET[ 'debug' ] == 'secret' && $current_user->user_level > 7  )
 define( 'WP_DEBUG', true );

Great, useful as always, thanks ! @nexik - neat idea.

Pingback: WordPress: Oh Those Actions and Filters!

@nexik: when WP loads wp-config.php, functions such as the one getting info for the current user are not loaded.

The proper way to implement what you suggest is with a simple plugin:

add_action( 'init', 'my_debug');
function my_debug() {
   if( current_user_can('update_plugins')
       && isset( $_GET['debug'] )
       && $_GET['debug'] == 'secret'
       && !defined( 'WP_DEBUG' )
   ) { define( 'WP_DEBUG', true ); }
}

(hope the comment formatting won't crap out this)

The comment formatting actually makes it look great ;)

The Yoast suggestion on the wp-config file work fine but this code like a plugin don't work. Some idea?

Unfortunately it's too late here to define WP_DEBUG. Really, the only way to do this is to have a 'secret' as said.

As long as you are logging WP_DEBUG instead of displaying it, you're in better shape. Just don't show them to the user.

That's so simple that it makes me angry that I did not think of it myself! :)
Great tip, thanks.

Pingback: links for 2010-08-18 | Links | WereWP

Yeah, this is pretty neat. Why didn't I know about this when I was puzzled by al that WP code, functions etcetera.. giving me more whitescreens than my frustration could handle.. ;)

Unfortunately I have the WSOD on the Dashboard and it doesn't work there ... I disabled the
Dashboard:

to avoid the WSOD, any ideas?

ups ... I meant

>?php //wp_dashboard(); ?<

haha, stilt not quite ... :-D

Hi guys, im really a freaking noob here...hehe

just one question though, can i just add the code directly to wp-config.php

i was actually trying to have my blog on debug mode to check on something.,

peace out

Yes. :)

wow, thanks for the quick reply..:)

peace out

hi !
I've got a bug, but it doesn't cause a white page, it create a big mess when I write a new post (i.e. it erases lines of text when i add a new line between 2 paragraphs, it put a whole paragraph in H2, asl...)

so can i use this tip in order to fix it ? how ? i've been trying several things since now but it failed...

thx for help !

Pingback: August 20, 2010 | Throwing a Brick

Pingback: links for 2010-08-25 « Stevens Media

I copied/pasted both Yoost original code and nexik admin code in the wp-config.php file -
and changed the third debug to my own secret word.
(and tried with the original ?debug=debug too)

but the only thing that happened was that the code-snippet was shown in the admin-page
and in the pages on the blog. (on top of the page)
and when pasting in the execution-snippet - nothing happens...
is there something I am missing here...?

regards

mike

Pingback: Configuring XAMPP as a Wordpress development server - memeLab: Web Publishing

I'm having the same problem as Mike, and I notice that the link to the debug=true for this page is no longer working (I saw it a week or so ago). Perhaps something changed in a WP release?

Yeah I disabled that on purpose :) has nothing to do with an upgrade :)

Pingback: Yoast: Quick Tip: Simple WordPress debugging | SEOBlog

Comments closed, if you feel you have something to say:
drop me a line.