WordPress 5min Read

How to enable WordPress Debug log

By Golam Mostafa Jul 25, 2021
Human Written

WP DEBUG is a permanent global variable in PHP that can be used to activate the “debug” mode in WordPress. It is assumed to be false by default, but on development copies of WordPress, it is usually set to true in the wp-config.php file.

When enabled, WordPress debug will log any errors detected on your site. This can be key to finding the source of an issue or just learning more details about any possible errors on your site.

In this blog, we’ll discuss how to enable WordPress to debug logs via wp-config.php file edit.

Why need to enable debug log on WordPress?

If you can display your WordPress errors, must enable debug logs. If you enable a debug log option, then WordPress will generate error logs and display error details on your website view page.

You’re a WordPress Developer and can develop your WordPress site, you can enable debug mode for finding errors.

How to enable debug mode using the wp-config file?

First, open your wp-config.php file in any text editor to edit this file and follow some steps.

Enable debugging:

define( 'WP_DEBUG', true );

Disable debugging:

define( 'WP_DEBUG', false );

How to display error logs on the WordPress site?

WP DEBUG LOG and WP DEBUG DISPLAY are PHP constants that extend WP DEBUG and can be used to debug WordPress as well.

You’ll also discuss, in this section, how to enable SCRIPT_DEBUG to display JavaScript errors.

WP_DEBUG_LOG:

WP DEBUG LOG is a plugin that works with WP DEBUG to save all errors to a debug.log log file in the /wp-content/ directory.

// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', false );

Copy and paste this code following the screenshot.

Enable debug log:

define( 'WP_DEBUG_LOG', true );

-or-

define( 'WP_DEBUG_LOG', '/tmp/wp-errors.log' );

Note: for WP_DEBUG_LOG to do anything, WP_DEBUG must be enabled (true). Remember, you can turn off WP_DEBUG_DISPLAY independently.

WP_DEBUG_DISPLAY:

WP DEBUG DISPLAY is a companion to WP DEBUG that determines whether or not debug messages are displayed within the HTML of pages.

The default value is ‘true,’ which displays errors and warnings as they occur. If you set this to false, all mistakes will be hidden. This should be used in conjunction with WP DEBUG LOG to allow for subsequent analysis of failures.

// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

Copy and paste this code following the screenshot to display WordPress errors.

Viewing the debug log:

Then, you can return to your site files and open https://yoursitename.com/wp-content/debug.log

SCRIPT_DEBUG:

SCRIPT_DEBUG is a related constant that will force WordPress to use the “dev” versions of core CSS and JavaScript files rather than the minified versions that are normally loaded. This is useful when you are testing modifications to any built-in .js or .css files. The default is false.

// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define( 'SCRIPT_DEBUG', true );

Bonus Tips:

SAVE QUERIES:

The SAVEQUERIES definition saves the database queries to an array, and that array can be displayed to help analyze those queries. The constant defined as true causes each query to be saved, how long that query took to execute, and what function called it.

define( 'SAVEQUERIES', true );

PHP Errors, Warnings, and Notices

Enabling WP_DEBUG will cause all PHP errors, notices, and warnings to be displayed. This is likely to modify the default behavior of PHP, which only displays fatal errors or shows a white screen of death when errors are reached.

Showing all PHP notices and warnings often results in error messages for things that don’t seem broken, but do not follow proper data validation conventions inside PHP. These warnings are easy to fix once the relevant code has been identified, and the resulting code is almost always more bug-resistant and easier to maintain.

Custom PHP Debugging

If it is necessary to log non-error information for debugging purposes, PHP does offer the error_log function for this purpose. However, this method does not provide properly formatted output by default.

To address this, you may add another function on your site to handle formatting, either by creating a custom plugin or using a snippet with some code snippets plugin. The function will act as a wrapper for the error_log using print_r to format arrays and objects correctly before logging them.

Below is an example function that requires WP_DEBUG to be enabled.

function write_log( $data ) { if ( true === WP_DEBUG ) { if ( is_array( $data ) || is_object( $data ) ) { error_log( print_r( $data, true ) ); } else { error_log( $data ); } }
}

Usage Examples:

write_log( 'DEBUG TEXT' );
write_log( $variable );

Note: It is not recommended to add custom code like the above example in functions.php to avoid maintenance, security, performance, compatibility, and code organization issues.

You may connect with us on Facebook and X. Also, check out our YouTube channel to view videos.

cleanly

Build better WordPress workflows with ThemeDev

Explore plugins, guides, and tools crafted for growing WordPress businesses.

Explore ThemeDev
Golam Mostafa
Written By

Golam Mostafa

I'm a senior plugin developer for WordPress. I have four years of experience working as a software engineer for ADB Bank, and in 2018, I started developing plugins and founded ThemeDev.

Keep Reading

View All
25+ Best Google Alternative Search Engines to Use in 2026
SEO 28min Read

25+ Best Google Alternative Search Engines to Use in 2026

Google is the most popular search engine, but it is not the only choice. Many other Google alternati...

Read Full Article
Mehrin Ferdous Mim
Mehrin Ferdous Mim Jan 30, 2025
WP Fastest Cache vs WP Super Cache vs Next3 Offload: Which One Is Better for Your Website?
Next3 Offload 14min Read

WP Fastest Cache vs WP Super Cache vs Next3 Offload: Which One Is Better for Your Website?

Are you confused when comparing WP Fastest Cache vs WP Super Cache vs Next3 Offload?  This blog...

Read Full Article
Mehrin Ferdous Mim
Mehrin Ferdous Mim Apr 21, 2024
The ultimate collection: best WordPress security plugins
WordPress Plugins 18min Read

The ultimate collection: best WordPress security plugins

Are you looking for WordPress security plugins? Well, you’re in the right place. We know WordPress...

Read Full Article
Editorial Staff
Editorial Staff Dec 23, 2023

Get WordPress Growth Tips Weekly

Join ThemeDev readers getting practical WordPress, plugin, and business growth resources delivered to their inbox.