WordPress has many built-in functions that can help you debug. They can be activated by editing them in the wp-config.php file:
1. Enable debug mode
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.
2. Display error messages
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 );

3. Enable error log
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‘ );
4. Disable Fatal error handler
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:
- What is ℹ️ Data breach (information disclosure) and How to prevent WordPress information disclosure
- What is ⚠️ Path disclosure and How to prevent WordPress full path disclosure (FPD)
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 );

5. Display database queries
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