wp-admin » How to properly DEBUG in WordPress ✔️

How to properly DEBUG in WordPress ✔️

WordPress has many built-in functions that can help you debug. They can be activated by editing them in the wp-config.php file:

By default Debug mode is disabled in WordPress, so you need to enable it by editing the wp-config.php file and changing the value from define( ‘WP_DEBUG’, false ); to define( ‘WP_DEBUG’, true );

define( 'WP_DEBUG', true );
chrome 1SVVMwZc4d - How to properly DEBUG in WordPress ✔️

Enabling WP_DEBUG will start displaying error messages directly on the page where they occur.


Enabling WP_DEBUG will start displaying error messages directly on the page where they occur, to disable this, and only record errors in a log file, add the following to wp-config.php

define( 'WP_DEBUG_DISPLAY', false );
chrome CYlAtmI0NB - How to properly DEBUG in WordPress ✔️

To enable the error log add the following to the wp-config.php file:

define( 'WP_DEBUG_LOG', true );
chrome Hleo7jrtmz - How to properly DEBUG in WordPress ✔️

Enabling WP_DEBUG_LOG will create a new file debug.log and write all error messages to that file. You can also set a custom file using: define( ‘WP_DEBUG_LOG’, ‘/tmp/site-errors.log‘ );


Since WP 5.2, when a fatal error occurs you only see the message:

image 8 - How to properly DEBUG in WordPress ✔️

This is done for security purposes so that for example, visitors don’t accidentally find out sensitive information:

See also  How to send AJAX requests in a WordPress theme or plugins

To see the entire error message directly on the page when it occurs, you can disable the fatal error handler by adding the following in your wp-config.php file:

define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );
chrome ZaNlSWG2v4 - How to properly DEBUG in WordPress ✔️

The SAVEQUERIES wp-config constant saves database queries to an array and We can use that array to display queries. The information saves each query, what function called it, and how long that query took to execute.

To enable query login you can add the following to wp-config.php

define( 'SAVEQUERIES', true );
chrome zWMkweBKsn - How to properly DEBUG in WordPress ✔️

This will save all database queries on a given page to a global variable $wpdb->queries

Here is a quick guide on how to view those queries: Save database queries for analysis in WordPress


Was this post helpful?

Leave a Comment

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Recommended