Debug statements in WordPress can be displayed by using echo which will display the message on the page. It’s a bit of a messy way to debug but works for simple debugging purposes. A better way to do this is to create a function to write your own debug statements to the debug.log file.
Debug Statements
Here’s a function you can use which will only logs the message if WP_DEBUG is enabled.
1 2 3 4 5 6 7 8 9 10 11 |
if (!function_exists('write_log')) { 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 ); } } } } |
Then you can call the write log function like this to send a message to the debug file!
1 |
write_log 'This is a message for debugging purposes'; |