We’ve all been there – Why wont’ it Work?
So you’ve been building WordPress websites for a while now. No doubt you’ll have come across a situation where you just can’t figure out why your code isn’t working the way you expected. This is especially true if you’re building your own themes and/or plugins. Wouldn’t it be great if someone could just tell you what the problem was?
The dreaded white screen of death (well known to PHP developers), missing content, and a host of other problems really should be much easier to troubleshoot. Unfortunately, we all know this isn’t the case. Many errors are simply not logged in a default WordPress install. This is a big factor when it comes to the difficulties some people find debugging their own code.
Why is logging turned off I hear you ask?
This is because WordPress controls logging with a few built-in assumptions.
A website that’s LIVE, serving information to customers simply doesn’t look good with errors all over the screen. Add to this, the fact that WordPress is commonly used by DIY’ers, startup businesses and the like, and it’s pretty clear that NOT displaying errors makes a bit of sense. So if they’re not preventing critical functions from being performed, why show them?
For this reason, errors are generally suppressed in WordPress, not simply regurgitated on screen.
Aren’t there other logs I can use?
What confuses many though is the lack of information in the logs. Sure, there’s the PHP and Apache logs, but what happens if you use a deprecated function. What if your plugin or theme isn’t using the right hook or filter syntax?
Fortunately there’s a solution. This method allows you to log all errors whether they’re WordPress specific or not. This let’s you future-proof your website build by recording information on all errors and warnings. This includes warnings about functions that are “soon-to-be” deprecated, allowing you to code with more confidence.
So how can I effectively troubleshoot errors in WordPress?
You can activate this level of logging by editing the wp-config.php file and replacing the following line…
// Turns on debugging
// Enables the logfile, located under the wp-content folder
// Forces regular versions of scripts to load (rather than minified versions)
// Disable the display of errors and warnings
This will automatically record all warnings, errors and notices to a file called “debug.log”, located in your wp-content directory.
You can find more information on WordPress debugging here: http://codex.wordpress.org/Debugging_in_WordPress.