My WP Trek

Playing with WordPress

WordPress Debug Function

WordPress easy debugging function,

Function that I use most of the time while printing out the output. This function is used specially when output are processed in background and print function will not display outputs. Then this function will comes handy which will log the output. Now we can check debug log to see what is going on.

function write_log( $log ) {
       if ( true === WP_DEBUG ) {
		if ( is_array( $log ) || is_object( $log ) ) {
			error_log( print_r( $log, true ) );
		} else {
			error_log( $log );
  • error_log()Send an error message to the defined error handling routines.
  • is_array()Finds whether a variable is an array.
  • print_r() Prints human-readable information about a variable.
WordPress Debug Function

Leave a Reply

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

Scroll to top