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 );

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 );

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

define( 'WP_DEBUG_LOG', true );

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:

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

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 );

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 );

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