L'evoluzione della comunicazione dalla sua creazione - Realisaprint.it
Con lo sviluppo della televisione e della radio, la pubblicità è esplosa. L'informazione è diventata internazionale e non ha più confini. È in ...
Debugging in WordPress
Notice: La funzione WP_Scripts::localize è stata richiamata in maniera scorretta. Il parametro `$l10n` deve essere un array. Per passare dati arbitrari agli script, usa la funzione `wp_add_inline_script()`. Leggi <anchor>Debugging in WordPress</anchor> per maggiori informazioni. (Questo messaggio è stato aggiunto nella versione 5.7.0.) in /home/www/realisaprint.com/attualita/wp-includes/functions.php on line 6085
Debugging in WordPress – Advanced Administration Handbook | Developer.WordPress.org
Debugging in WordPress – Advanced Administration Handbook \| Developer.WordPress.org

[WordPress.org](https://wordpress.org/)

- [News](https://wordpress.org/news/)
- [Showcase](https://wordpress.org/showcase/)
- [Hosting](https://wordpress.org/hosting/)
- Extend
  - [Themes](https://wordpress.org/themes/)
  - [Plugins](https://wordpress.org/plugins/)
  - [Patterns](https://wordpress.org/patterns/)
  - [Blocks](https://wordpress.org/blocks/)
  - [Openverse ↗︎](https://openverse.org/)
- Learn
  - [Learn WordPress](https://learn.wordpress.org/)
  - [Documentation](https://wordpress.org/documentation/)
  - [Forums](https://wordpress.org/support/forums/)
  - [Developers](https://developer.wordpress.org/)
  - [WordPress.tv ↗︎](https://wordpress.tv/)
- Community
  - [Make WordPress](https://make.wordpress.org/)
  - [Photo Directory](https://wordpress.org/photos/)
  - [Five for the Future](https://wordpress.org/five-for-the-future/)
  - [Events](https://events.wordpress.org/)
  - [Job Board ↗︎](https://jobs.wordpress.net/)
- About
  - [About WordPress](https://wordpress.org/about/)
  - [Enterprise](https://wordpress.org/enterprise/)
  - [Gutenberg ↗︎](https://wordpress.org/gutenberg/)
- [Get WordPress](https://wordpress.org/download/)

Search in WordPress.org

[Get WordPress](https://wordpress.org/download/)

[WordPress.org](https://wordpress.org/)

[WordPress Developer Resources](https://developer.wordpress.org)

Debugging in WordPress


- [Developer Blog](https://developer.wordpress.org/news/)
- [Code Reference](https://developer.wordpress.org/reference/)
- [WP-CLI Commands](https://developer.wordpress.org/cli/commands/)

- [Developer Blog](https://developer.wordpress.org/news/)
- [Code Reference](https://developer.wordpress.org/reference/)
- [WP-CLI Commands](https://developer.wordpress.org/cli/commands/)

[Home](https://developer.wordpress.org)[Advanced Administration Handbook](https://developer.wordpress.org/advanced-administration/)[Debugging WordPress](https://developer.wordpress.org/advanced-administration/debug/)Debugging in WordPress

Search

# Debugging in WordPress

## In this article

Table of Contents

- [Example wp-config.php for Debugging](#example-wp-config-php-for-debugging)
- [WP\_DEBUG](#wp_debug)
  - [PHP Errors, Warnings, and Notices](#php-errors-warnings-and-notices)
  - [Custom PHP Debugging](#custom-php-debugging)
  - [Deprecated Functions and Arguments](#deprecated-functions-and-arguments)
- [WP\_DEBUG\_LOG](#wp_debug_log)
- [WP\_DEBUG\_DISPLAY](#wp_debug_display)
- [SCRIPT\_DEBUG](#script_debug)
- [SAVEQUERIES](#savequeries)
- [Debugging Plugins](#debugging-plugins)
- [Changelog](#changelog)

[↑ Back to top](#wp--skip-link--target)

Debugging PHP code is part of any project, but WordPress comes with specific debug systems designed to simplify the process as well as standardize code across the core, plugins, and themes. This page describes the various debugging tools on WordPress and how to be more productive in your coding, as well as increasing the overall quality and interoperability of your code.

For non-programmers or general users, these options can be used to show detailed information about errors.

**NOTE**: Before making any modifications to your website, verify that you have either utilized a staging environment or taken an appropriate backup of your site.

## [Example wp-config.php for Debugging](\#example-wp-config-php-for-debugging)

The following code, inserted in your [wp-config.php](https://wordpress.org/documentation/article/editing-wp-config-php/) file, will log all errors, notices, and warnings to a file called `debug.log` in the `wp-content` directory. It will also hide the errors, so they do not interrupt page generation.

```
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

```

```
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );

```

```
// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

```

```
// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define( 'SCRIPT_DEBUG', true );

```

**NOTE**: You must insert this **BEFORE** `/* That's all, stop editing! Happy blogging. */` in the [wp-config.php](https://developer.wordpress.org/advanced-administration/wordpress/wp-config/) file.

## [WP\_DEBUG](\#wp_debug)

`WP_DEBUG` is a PHP constant (a permanent global variable) that can be used to trigger the “debug” mode throughout WordPress. It is assumed to be false by default, and is usually set to true in the [wp-config.php](https://developer.wordpress.org/advanced-administration/wordpress/wp-config/) file on development copies of WordPress.

```
// This enables debugging.
define( 'WP_DEBUG', true );

```

```
// This disables debugging.
define( 'WP_DEBUG', false );

```

**Note**: The `true` and `false` values in the example are not surrounded by apostrophes (‘) because they are boolean (true/false) values. If you set constants to `'false'`, they will be interpreted as true because the quotes make it a string rather than a boolean.

It is not recommended to use `WP_DEBUG` or the other debug tools on live sites; they are meant for local testing and staging installs.

### [PHP Errors, Warnings, and Notices](\#php-errors-warnings-and-notices)

Enabling `WP_DEBUG` will cause all PHP errors, notices, and warnings to be displayed. This is likely to modify the default behavior of PHP, which only displays fatal errors or shows a white screen of death when errors are reached.

Showing all PHP notices and warnings often results in error messages for things that don’t seem broken, but do not follow proper data validation conventions inside PHP. These warnings are easy to fix once the relevant code has been identified, and the resulting code is almost always more bug-resistant and easier to maintain.

### [Custom PHP Debugging](\#custom-php-debugging)

If it is necessary to log non-error information for debugging purposes, PHP does offer the `error_log` function for this purpose. However, this method does not provide properly formatted output by default.

To address this, you may add another function on your site to handle formatting, either by creating a [custom plugin](https://developer.wordpress.org/plugins/plugin-basics/) or using a snippet with some [code snippets](https://wordpress.org/plugins/search/code+snippets/) plugin. The function will act as a wrapper for the `error_log` using `print_r` to format arrays and objects correctly before logging them.

Below is an example function that requires `WP_DEBUG` to be enabled.

```
function write_log( $data ) {
    if ( true === WP_DEBUG ) {
        if ( is_array( $data ) || is_object( $data ) ) {
            error_log( print_r( $data, true ) );
        } else {
            error_log( $data );
        }
    }
}

```

Usage Examples:

```
write_log( 'DEBUG TEXT' );
write_log( $variable );

```

**Note**: It is not recommended to add custom code like the above example in `functions.php` to avoid maintenance, security, performance, compatibility, and code organization issues.

### [Deprecated Functions and Arguments](\#deprecated-functions-and-arguments)

Enabling `WP_DEBUG` will also cause notices about deprecated functions and arguments within WordPress that are being used on your site. These are functions or function arguments that have not been removed from the core code yet, but are slated for deletion in the near future. Deprecation notices often indicate the new function that should be used instead.

## [WP\_DEBUG\_LOG](\#wp_debug_log)

`WP_DEBUG_LOG` is a companion to WP\_DEBUG that causes all errors to also be saved to a `debug.log` log file. This is useful if you want to review all notices later or need to view notices generated off-screen (e.g. during an AJAX request or `wp-cron` run).

Note that this allows you to write to a log file using PHP’s built in `error_log()` function, which can be useful for instance when debugging Ajax events.

When set to `true`, the log is saved to `debug.log` in the content directory (usually `wp-content/debug.log`) within your site’s file system. Alternatively, you can set it to a valid file path to have the file saved elsewhere.

```
define( 'WP_DEBUG_LOG', true );

```

-or-

```
define( 'WP_DEBUG_LOG', '/tmp/wp-errors.log' );

```

**Note**: for `WP_DEBUG_LOG` to do anything, `WP_DEBUG` must be enabled (true). Remember, you can turn off `WP_DEBUG_DISPLAY` independently.

## [WP\_DEBUG\_DISPLAY](\#wp_debug_display)

`WP_DEBUG_DISPLAY` is another companion to `WP_DEBUG` that controls whether debug messages are shown inside the HTML of pages or not. The default is ‘true’ which shows errors and warnings as they are generated. Setting this to false will hide all errors. This should be used with `WP_DEBUG_LOG` so that errors can be reviewed later.

```
define( 'WP_DEBUG_DISPLAY', false );

```

**Note**: for `WP_DEBUG_DISPLAY` to do anything, `WP_DEBUG` must be enabled (true). Remember, you can control `WP_DEBUG_LOG` independently.

## [SCRIPT\_DEBUG](\#script_debug)

`SCRIPT_DEBUG` is a related constant that will force WordPress to use the “dev” versions of core CSS and JavaScript files rather than the minified versions that are normally loaded. This is useful when you are testing modifications to any built-in `.js` or `.css` files. The default is `false`.

```
define( 'SCRIPT_DEBUG', true );

```

## [SAVEQUERIES](\#savequeries)

The `SAVEQUERIES` definition saves the database queries to an array, and that array can be displayed to help analyze those queries. The constant defined as true causes each query to be saved, how long that query took to execute, and what function called it.

```
define( 'SAVEQUERIES', true );

```

The array is stored in the global `$wpdb->queries`.

**NOTE**: This will have a performance impact on your site, so make sure to turn this off when you aren’t debugging.

## [Debugging Plugins](\#debugging-plugins)

There are many [debugging plugins](https://wordpress.org/plugins/search/debug/) for WordPress that show more information about the internals, either for a specific component or in general.

For example, [Debug Bar](https://wordpress.org/plugins/debug-bar/) adds a debug menu to the admin bar that shows query, cache, and other helpful debugging information. When WP\_DEBUG is enabled, it also tracks PHP Warnings and Notices to make them easier to find.

## [Changelog](\#changelog)

- 2023-02-01: Updated original content.
- 2022-09-11: Original content from [Debugging in WordPress](https://wordpress.org/documentation/article/debugging-in-wordpress/); ticket from [Github](https://github.com/WordPress/Documentation-Issue-Tracker/issues/349).

First published

March 28, 2023

Last updated

January 16, 2024

Edit article

[Improve it on GitHub: Debugging in WordPress](https://github.com/WordPress/Advanced-administration-handbook/edit/main/debug/debug-wordpress.md)

Changelog

[See list of changes: Debugging in WordPress](https://github.com/WordPress/Advanced-administration-handbook/commits/main/debug/debug-wordpress.md)

[PreviousDebugging WordPressPrevious: Debugging WordPress](https://developer.wordpress.org/advanced-administration/debug/)

[NextDebugging a WordPress NetworkNext: Debugging a WordPress Network](https://developer.wordpress.org/advanced-administration/debug/debug-network/)

## Chapters

Chapter list

- [Advanced Administration Handbook](https://developer.wordpress.org/advanced-administration/)
- [Before You Install](https://developer.wordpress.org/advanced-administration/before-install/)
  - [Creating Database for WordPress](https://developer.wordpress.org/advanced-administration/before-install/creating-database/)
  - [How to install WordPress](https://developer.wordpress.org/advanced-administration/before-install/howto-install/)
  - [Running a Development Copy of WordPress](https://developer.wordpress.org/advanced-administration/before-install/development/)
  - [Installing WordPress in your language](https://developer.wordpress.org/advanced-administration/before-install/in-your-language/)
  - [Installing Multiple WordPress Instances](https://developer.wordpress.org/advanced-administration/before-install/multiple-instances/)
  - [Install WordPress at popular providers](https://developer.wordpress.org/advanced-administration/before-install/popular-providers/)
- [Server configuration](https://developer.wordpress.org/advanced-administration/server/)
  - [Changing File Permissions](https://developer.wordpress.org/advanced-administration/server/file-permissions/)
  - [Finding Server Info](https://developer.wordpress.org/advanced-administration/server/server-info/)
  - [Giving WordPress Its Own Directory](https://developer.wordpress.org/advanced-administration/server/wordpress-in-directory/)
  - [Configuring Wildcard Subdomains](https://developer.wordpress.org/advanced-administration/server/subdomains-wildcard/)
  - [Emptying a Database Table](https://developer.wordpress.org/advanced-administration/server/empty-database/)
  - [Web servers](https://developer.wordpress.org/advanced-administration/server/web-server/)
    - [Apache HTTPD / .htaccess](https://developer.wordpress.org/advanced-administration/server/web-server/httpd/)
    - [Nginx](https://developer.wordpress.org/advanced-administration/server/web-server/nginx/)
  - [Control Panels](https://developer.wordpress.org/advanced-administration/server/control-panel/)
- [WordPress configuration](https://developer.wordpress.org/advanced-administration/wordpress/)
  - [Editing wp-config.php](https://developer.wordpress.org/advanced-administration/wordpress/wp-config/)
  - [Site Architecture (v1.5)](https://developer.wordpress.org/advanced-administration/wordpress/site-architecture/)
  - [Post Formats](https://developer.wordpress.org/advanced-administration/wordpress/post-formats/)
  - [Cookies](https://developer.wordpress.org/advanced-administration/wordpress/cookies/)
  - [Update Services](https://developer.wordpress.org/advanced-administration/wordpress/update-services/)
  - [Editing Files](https://developer.wordpress.org/advanced-administration/wordpress/edit-files/)
  - [CSS](https://developer.wordpress.org/advanced-administration/wordpress/css/)
  - [WordPress Feeds](https://developer.wordpress.org/advanced-administration/wordpress/feeds/)
  - [Multilingual WordPress](https://developer.wordpress.org/advanced-administration/wordpress/multilingual/)
  - [oEmbed](https://developer.wordpress.org/advanced-administration/wordpress/oembed/)
  - [Loopbacks](https://developer.wordpress.org/advanced-administration/wordpress/loopback/)
  - [Importing Content](https://developer.wordpress.org/advanced-administration/wordpress/import/)
  - [Common WordPress errors](https://developer.wordpress.org/advanced-administration/wordpress/common-errors/)
- [Upgrading / Migration](https://developer.wordpress.org/advanced-administration/upgrade/)
  - [Updating WordPress using FTP](https://developer.wordpress.org/advanced-administration/upgrade/ftp/)
    - [Using FileZilla](https://developer.wordpress.org/advanced-administration/upgrade/ftp/filezilla/)
  - [phpMyAdmin](https://developer.wordpress.org/advanced-administration/upgrade/phpmyadmin/)
  - [Upgrading WordPress](https://developer.wordpress.org/advanced-administration/upgrade/upgrading/)
  - [Migrating WordPress](https://developer.wordpress.org/advanced-administration/upgrade/migrating/)
- [WordPress Multisite / Network](https://developer.wordpress.org/advanced-administration/multisite/)
  - [Before You Create A Network](https://developer.wordpress.org/advanced-administration/multisite/prepare-network/)
  - [Create A Network](https://developer.wordpress.org/advanced-administration/multisite/create-network/)
  - [WordPress Multisite Domain Mapping](https://developer.wordpress.org/advanced-administration/multisite/domain-mapping/)
  - [Multisite Network Administration](https://developer.wordpress.org/advanced-administration/multisite/administration/)
  - [Network Admin](https://developer.wordpress.org/advanced-administration/multisite/admin/)
    - [Network Admin Settings Screen](https://developer.wordpress.org/advanced-administration/multisite/admin/settings/)
  - [Migrate WordPress sites into WordPress Multisite](https://developer.wordpress.org/advanced-administration/multisite/sites-multisite/)
- [Plugins](https://developer.wordpress.org/advanced-administration/plugins/)
  - [File Editor Screen](https://developer.wordpress.org/advanced-administration/plugins/editor-screen/)
  - [Must Use Plugins](https://developer.wordpress.org/advanced-administration/plugins/mu-plugins/)
- [Themes](https://developer.wordpress.org/advanced-administration/themes/)
- [Security](https://developer.wordpress.org/advanced-administration/security/)
  - [Your password](https://developer.wordpress.org/advanced-administration/security/logging-in/)
  - [Two Step Authentication](https://developer.wordpress.org/advanced-administration/security/mfa/)
  - [Backups](https://developer.wordpress.org/advanced-administration/security/backup/)
    - [Backing Up Your Database](https://developer.wordpress.org/advanced-administration/security/backup/database/)
    - [Backing Up Your WordPress Files](https://developer.wordpress.org/advanced-administration/security/backup/files/)
  - [HTTPS](https://developer.wordpress.org/advanced-administration/security/https/)
  - [Brute Force Attacks](https://developer.wordpress.org/advanced-administration/security/brute-force/)
  - [Hardening WordPress](https://developer.wordpress.org/advanced-administration/security/hardening/)
    - [Display Errors](https://developer.wordpress.org/advanced-administration/security/hardening/display-errors/)
  - [Monitoring](https://developer.wordpress.org/advanced-administration/security/monitoring/)
- [Performance / Optimization](https://developer.wordpress.org/advanced-administration/performance/)
  - [Cache](https://developer.wordpress.org/advanced-administration/performance/cache/)
  - [Optimization](https://developer.wordpress.org/advanced-administration/performance/optimization/)
  - [PHP Optimization](https://developer.wordpress.org/advanced-administration/performance/php/)
- [Debugging WordPress](https://developer.wordpress.org/advanced-administration/debug/)
  - [Debugging in WordPress](https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/)
  - [Debugging a WordPress Network](https://developer.wordpress.org/advanced-administration/debug/debug-network/)
  - [Using Your Browser to Diagnose JavaScript Errors](https://developer.wordpress.org/advanced-administration/debug/debug-javascript/)
  - [Test Driving WordPress](https://developer.wordpress.org/advanced-administration/debug/test-driving/)
  - [Version Control](https://developer.wordpress.org/advanced-administration/debug/version-control/)
- [Resources for Building on WordPress](https://developer.wordpress.org/advanced-administration/resources/)
  - [FAQ Troubleshooting](https://developer.wordpress.org/advanced-administration/resources/faq/)

- [About](https://wordpress.org/about/)
- [News](https://wordpress.org/news/)
- [Hosting](https://wordpress.org/hosting/)
- [Privacy](https://wordpress.org/about/privacy/)

- [Showcase](https://wordpress.org/showcase/)
- [Themes](https://wordpress.org/themes/)
- [Plugins](https://wordpress.org/plugins/)
- [Patterns](https://wordpress.org/patterns/)

- [Learn](https://learn.wordpress.org/)
- [Documentation](https://wordpress.org/documentation/)
- [Developers](https://developer.wordpress.org/)
- [WordPress.tv ↗](https://wordpress.tv/)

- [Get Involved](https://make.wordpress.org/)
- [Events](https://events.wordpress.org/)
- [Donate ↗](https://wordpressfoundation.org/donate/)
- [Five for the Future](https://wordpress.org/five-for-the-future/)

- [WordPress.com ↗](https://wordpress.com/?ref=wporg-footer)
- [Matt ↗](https://ma.tt/)
- [bbPress ↗](https://bbpress.org/)
- [BuddyPress ↗](https://buddypress.org/)

[WordPress.org](https://wordpress.org/)[WordPress.org](https://wordpress.org/)

- [Visit our Facebook page](https://www.facebook.com/WordPress/)
- [Visit our X (formerly Twitter) account](https://www.x.com/WordPress)
- [Visit our Instagram account](https://www.instagram.com/wordpress/)
- [Visit our LinkedIn account](https://www.linkedin.com/company/wordpress)
- [Visit our YouTube channel](https://www.youtube.com/wordpress)

![Code is Poetry](https://s.w.org/style/images/code-is-poetry-for-dark-bg.svg)