How to debug your WordPress site? | AltusHost

How to debug your WordPress site?

How to debug your WordPress site?

Altus Host


You are having a WordPress website and the headline seems oddly familiar? Sudden pop out of error has occurred definitely to anyone having a website at least once. 

It can be very frustrating, especially if you’re not quite sure what the problem is. However, there is a solution for everything!

WordPress has a lot of built-in features that can help you detect and fix problems. Functions are being activated by editing them to the wp-config.php file.

Continue reading if you are interested in learning the easiest way to diagnose problems with your WordPress site.

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 );
chrome 1SVVMwZc4d - How to properly DEBUG in WordPress ✔️

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 );
chrome CYlAtmI0NB - How to properly DEBUG in WordPress ✔️

3. Enable error log

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

4. Disable Fatal error handler

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:

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 ✔️

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

To display these queries on every page you can add the following code inside the theme’s footer.php file:

<?php
if ( current_user_can( 'administrator' ) ) {
 global $wpdb;
 echo "<pre>";
 print_r( $wpdb->queries );
 echo "</pre>";
}
?>

After you’ve done everything, at the bottom of every page of the website you can see queries 

Keep in mind that this will further affect the performance and speed of your WordPress site, so be sure to turn off the above features after the work is completed.

If you think this material is valuable to WordPress comunnity, share it with your friends! Let’s spread the know-how!

And let us know in the comments below what other WordPress themes you want us to cover. 

Website | + posts

Recent Articles

Tags