Easy WordPress Debugging Tips

In case you didn’t know, debugging in WordPress is essential. Not only does it save users from plugin conflicts and enormous headaches but it is a valuable learning tool to help you code more cleanly and efficiently.

The following are some easy tips to get you started:

  1. var_dump() and print_r()
    Put any variable inside one of these two functions and see what it’s made of. print_r() will even return a value. If you ever wonder what your code is doing (or why it doesn’t work) this is a good place to start.

  2. WP_DEBUG()
    is a constant in your config.php file. Set it to 'true'in your development environment and 'false' in production. This will display both warnings and fatal errors. Warning are often due to uninitialised variables and conditions that don’t have alternative else statements. A must if you are developing a theme or plugin!

  3. WP_DEBUG_LOG and WP_DEBUG_DISPLAY
    So let’s say you’re debugging on a staging or a production server. You want to log any errors but you don’t don’t them to be visible as that would be ugly and also make your site more vulnerable. These guys are your friends. All you need to do is have this little snippet in your config.php file and your errors will be logged to a file named debug.log file that will be generated inside the wp-content directory. Please note that you actually have to have errors for this to work.

Some of this may seem obvious for tried and true php developers but for anyone new to WordPress theme or plugin development these can make the difference between code that throws errors (and uses memory to do so) and efficient application of code. WordPress debugging is also invaluable when trying to modify or use copied and pasted code.

Further Resources …

Leave a Reply

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

Click to view allowed tags

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>