Wordpress - error_log() output for print_r() appearing on page
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 ) );
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 ) );