I am trying to debug a plugin and am using error_log() in various places to see what various things are. I am using the following:

error_log( print_r( $variable ) );

When I look at debug.log, all I see is 1 and the actual output of the error_log() function is sent to the browser instead.

I know another plugin is not doing this as all are disabled with the exception of the one I am writing and in my wp-config.php I define WP_DEBUG_DISPLAY as false.

The same thing happens if I use var_dump() and var_export() as well. Other functions like gettype() and such are working just fine.

Any way to get the output back into debug.log?


The print_r function accept second parameter for return so it retrun the variable instead of printing it.

print_r($expression, $return)

So you can do

error_log( print_r( $variable, true ) );
  • Thanks. Figured it would be something that simple that I was missing :) – Cedon Dec 17 '17 at 0:17

If your variable is just a string, then you can simply use error_log ( $variable ). If it's an object or an array, other than using print_r(), you can serialize it too:

error_log ( serialize ( $variable ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.