Skip to content

Instantly share code, notes, and snippets.

@insaurabh
Last active January 17, 2019 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insaurabh/a1332a3562e017a8ca51be766c77db14 to your computer and use it in GitHub Desktop.
Save insaurabh/a1332a3562e017a8ca51be766c77db14 to your computer and use it in GitHub Desktop.
How to write log in wordpress from child theme.
// add in child theme function.php
// For more info : https://codex.wordpress.org/Debugging_in_WordPress
// Step 1 : define( 'WP_DEBUG', true );
// Step 2 : define( 'WP_DEBUG_LOG', true );
// Step 3 : Paste the below code in child theme function.php
// Step 4 : Call the function as : hb_write_log('lets debug');
// Step 5 : See the logs @ /website-entry-point/wp-content/debug.log ( if there is no file create a one with same name.)
if (!function_exists('hb_write_log')) {
function hb_write_log($log) {
if (true === WP_DEBUG) {
if (is_array($log) || is_object($log)) {
error_log(print_r($log, true));
} else {
error_log($log);
}
}
}
}
// call like below.
hb_write_log('lets debug')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment