I am developing a custom code in wordpress and in order to debug that I need to know if I can add custom text in wpdebug log Please help me if i can do it
2 Answers
Hello Please add following code snippet in your theme’s functions.php file
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 );
}
}
}
}
Now you can add custom log as and when you wish by using following output
write_log('THIS IS THE START OF MY CUSTOM DEBUG');
write_log($your_variable);
Do let me know if you have any queries.