Handy WordPress Debugging and Logging in Development

This handy WordPress debugging and logging snippet during development will help no end when developing themes or plugins, it is always a good idea to have these switched on in the WordPress wp-config.php file.

Replace in wp-config.php

define('WP_DEBUG', false);


define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

Then for helpful logging of values and arrays to the debug.log file add this snippet to the wp-config.php below the previous code:

  function _log( $message ) {
    if( WP_DEBUG === true ){
      if( is_array( $message ) || is_object( $message ) ){
        error_log( print_r( $message, true ) );
      } else {
        error_log( $message );

Then whenever you need to log anything use

_log( $somevalue );

Source – http://fuelyourcoding.com/simple-debugging-with-wordpress/


London based web developer. Creator of Instagrate Pro. Loves WordPress and ribs.

Leave a Reply

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