Create Custom Menu in WordPress Dashboard
Complete tutorial on create custom menu in wordpress dashboard. Discover practical examples, implementation tips, and expert advice for WordPress and WooCo
Read More βRelying on simple `var_dump()` or `print_r()` on a live screen can break your site layout or expose sensitive data to users. A more professional approach is to use PHP's native `error_log()` system integrated with WordPress's debug mode. By defining a custom `write_log()` wrapper, you can easily send strings, arrays, or complex objects to a hidden file on your server. This allows you to track background processes, AJAX responses, and silent errors without interrupting the user experience or compromising your site's front-end integrity.
Need a reliable way to track bugs in WordPress? This tutorial walks you through setting up a custom write_log() function using PHP's error_log() to simplify debugging.
Define the write_log() Function
Here's how to use error_log() conditionally with WP_DEBUG:
function write_log($message) {
if (true === WP_DEBUG) {
if (is_array($message) || is_object($message)) {
error_log(print_r($message, true));
} else {
error_log($message);
}
}
}
Why This Matters
Logging in Action
function my_debug_function() {
write_log('Debug started');
$test_array = ['key' => 'value'];
write_log($test_array);
}
Turn on Logging
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
Find the log in wp-content/debug.log or your server’s error log folder. Customize location via php.ini settings if needed.
Debugging Tips
WP_DEBUG = falseFurther Documentation
By using a tailored logging function, developers gain full control over debugging messages and performance monitoring in WordPress. 
Search our archives or reach out to our team for solutions and expert advice.