How To Debug WordPress

This article describes several settings you can use to help debug WordPress.

Table of Contents

 

  • WordPress Debug
  • Additional debugging options
  • Logging database queries
  • More Information
  •  

WORDPRESS DEBUG

WordPress includes several settings that you can use to help debug the main application, themes, your own custom code, and more.

Generally, these settings are intended for use by developers and should not be used on “live” sites. However, you can also use them in certain scenarios to help troubleshoot issues you may be experiencing with third-party code, such as plugins or themes.

To enable debugging mode in WordPress, follow these steps:

  1. Log in to cPanel, or access your account using SSH.
  2. Using the cPanel File Manager or the SSH command prompt, open the wp-config.php file in your preferred text editor.
  3. To enable debugging mode, add the following line to the wp-config.php file:
    define('WP_DEBUG', true); 
    When this setting is enabled, WordPress displays all PHP errors, notices, and warnings.
  4. Save your changes and exit the text editor. Debugging mode is now active.

    When you are done, disable debugging mode by modifying the line in the wp-config.php file as follows:

    define('WP_DEBUG', false);

ADDITIONAL DEBUGGING OPTIONS

There are several additional settings you can use to control the debugging information that WordPress provides:

  • WP_DEBUG_LOG: When WP_DEBUG_LOG and WP_DEBUG are enabled, WordPress saves all error information to the debug.log file in the wp-content directory. By default, this setting is disabled.
    To enable this setting, add the following line to the wp-config.php file:
    define('WP_DEBUG_LOG', true);
  • WP_DEBUG_DISPLAY: When WP_DEBUG_DISPLAY and WP_DEBUG are enabled, WordPress displays error and warning messages on web pages. By default, this setting is enabled. When this setting is disabled, debugging messages are hidden from view.
    To disable this setting, add the following line to the wp-config.php file:
    define('WP_DEBUG_DISPLAY', false);
  • SCRIPT_DEBUG: When SCRIPT_DEBUG is enabled, WordPress uses development versions of core CSS and JavaScript files instead of the compressed versions that it normally uses. By default, this setting is disabled. You can use this setting to test modifications to built-in .js or .css files.
    To enable this setting, add the following line to the wp-config.php file:
    define('SCRIPT_DEBUG', true);

LOGGING DATABASE QUERIES

If you are experiencing database issues with WordPress, you can enable query logging. When query logging is enabled, the following items are saved in the global $wpdb->queries array:

  • The actual database query.
  • How long the query takes to run.
  • The function that called the query.

To enable database query logging, add the following line to the wp-config.php file:

define('SAVEQUERIES', true);
Enabling this setting affects your site's performance. You should only enable this setting for as long as it is necessary to debug a problem and then disable it.

The following PHP code snippet demonstrates how to dump the entire contents of the $wpdb->queries array to a page:

<?php
    global $wpdb;
    print_r( $wpdb->queries );
?>

MORE INFORMATION

To view the official WordPress debugging documentation, please visit https://codex.wordpress.org/Debugging_in_WordPress.

  • 423 Kunder som kunne bruge dette svar
Hjalp dette svar dig?

Relaterede artikler

How To 1-Click Install WordPress With Softaculous

INSTALLING WORDPRESS You can have a WordPress site up and running in minutes by using the...

How To Secure Your WordPress Site

This article describes several ways to enhance the security of your WordPress site. ESSENTIAL...

How To Reset The WordPress Administrator Password

This article describes how to reset the WordPress administrator password. Normally, if you forget...

W3 Total Cache & GTmetrix To Optimize WordPress

As your site gains traffic and users, and as you add additional content, your site may begin to...

How To Add CAPTCHA Protection To WordPress

This article describes how to add CAPTCHA protection to a WordPress site using the Google Captcha...