Skip to content

WP_DEBUG_LOG and WP_DEBUG_DISPLAY: what each one does

WP_DEBUG turns debugging on, WP_DEBUG_LOG writes errors to a file and WP_DEBUG_DISPLAY shows them on the page. Set them safely in wp-config.php.

WP_DEBUG is the master switch for WordPress debugging, and the two constants people look up most decide where the errors go. WP_DEBUG_LOG writes them to a file. WP_DEBUG_DISPLAY prints them into the page. Neither does anything while WP_DEBUG is false. WP_DEBUG_DISPLAY defaults to true, so turning WP_DEBUG on and setting nothing else shows PHP notices to your visitors; that one default is behind most “my site is suddenly showing warnings” tickets. WP_DEBUG_LOG set to true writes to wp-content/debug.log. Since WordPress 5.1 you can give it an absolute path instead, which moves the log out of the web root where nobody can download it. The combination that is safe to leave on a live site is WP_DEBUG true, WP_DEBUG_DISPLAY false, and WP_DEBUG_LOG pointed at a path outside the web root.

What you’ll accomplish

  • Know what each of WP_DEBUG, WP_DEBUG_LOG, WP_DEBUG_DISPLAY and SCRIPT_DEBUG changes, and in what order WordPress reads them.
  • Put a wp-config.php block in place that logs everything and displays nothing, with the log file outside the docroot.
  • Gate the noisy settings by environment with WP_ENVIRONMENT_TYPE, so a staging config cannot leak into production.
  • Prove from the shell that the constants are live, that errors land in the file you chose, and that nothing reaches the browser.
  • Recognise the four ways this setup silently produces an empty log.

Prerequisites

  • WordPress 5.1 or newer for the string-path form of WP_DEBUG_LOG. WP_ENVIRONMENT_TYPE needs 5.5, and the fatal error handler discussed below arrived in 5.2. Everything else here has been stable since WordPress 3.x.
  • Write access to wp-config.php by SFTP, SSH or a file manager. A host that hides the file from you usually overrides these constants too, which troubleshooting covers.
  • Shell access for WP-CLI is helpful but not required — every change here can be made by editing the file directly.
  • A writable directory outside the docroot. On cPanel that is typically /home/USER/logs, since /home/USER/public_html is the docroot. On a container image with a read-only filesystem you may only have /tmp, which does not survive a restart.
  • Know which PHP handler you run. Under PHP-FPM the pool config can set php_admin_value[display_errors], which PHP refuses to let ini_set() override at runtime, so WordPress loses that argument.

How it works

The constants are read once, early, by one core function: wp_debug_mode(), called from wp-settings.php before any plugin, theme or must-use plugin loads. It implements no logging of its own. It reads your constants, translates them into two PHP ini settings — display_errors and error_log — and lets PHP do the rest. That is the whole mechanism, and it explains almost every surprise.

Decision flow showing WP_DEBUG as the master switch: when false, WP_DEBUG_LOG and WP_DEBUG_DISPLAY are read but change nothing; when true, error reporting rises to E_ALL and branches into WP_DEBUG_DISPLAY, which defaults to true and prints notices to visitors, and WP_DEBUG_LOG, which writes either to wp-content/debug.log or to an absolute path outside the docroot

Four consequences follow from that ordering.

Definitions after the wp-settings.php line are dead. The last statement in a stock wp-config.php is require_once ABSPATH . 'wp-settings.php';. Anything you define() below it runs after wp_debug_mode() has already decided, and PHP emits a “constant already defined” warning for good measure. Your block must sit above that line.

WP_DEBUG_DISPLAY has three meaningful values, not two. Set to a truthy value it calls ini_set('display_errors', 1). Set to false it calls ini_set('display_errors', 0). Set to null it does neither — WordPress leaves whatever php.ini or your FPM pool decided completely alone. If you want PHP to remain in charge of display, null is the value you want, and false is not.

WP_DEBUG_LOG is compared as a string. Core casts and lowercases the constant, treating true or '1' as a request for WP_CONTENT_DIR . '/debug.log'. Any other string is a literal path. That is why define( 'WP_DEBUG_LOG', '/var/log/wordpress/site.log' ) works, and why a typo in it fails silently: a typo is still a valid string, so core hands it to ini_set('error_log', ...), PHP cannot open it, and the errors go nowhere you will look.

REST, AJAX and XML-RPC requests always force display off. After the constant handling, wp_debug_mode() unconditionally sets display_errors to 0 for XML-RPC, REST, AJAX and JSON requests, so a notice cannot corrupt a JSON response body. “I see the error in the page but not in the REST response” is therefore expected behaviour, not a clue.

Core’s own reference for these constants is the WordPress debugging handbook, which is worth bookmarking for the constants this article does not cover.

Two related constants sit outside this flow. SCRIPT_DEBUG has nothing to do with PHP errors: it makes WordPress enqueue the unminified .js and .css files that ship with core instead of the .min builds, so a stack trace in the browser console points at a readable line. It only affects core and bundled scripts — a plugin that ships its own minified bundle usually ignores it entirely unless the author checked the constant. CONCATENATE_SCRIPTS is the related knob, and it only applies inside wp-admin, where core normally merges several scripts into one request; turning SCRIPT_DEBUG on disables that concatenation on its own.

WP_DISABLE_FATAL_ERROR_HANDLER is different again. Since WordPress 5.2, an uncaught fatal error is caught by core’s fatal error handler, which replaces the PHP error with the generic “There has been a critical error on this website” page and emails the admin a recovery link. Setting the constant to true disables that handler, so a fatal produces the ordinary PHP failure again — which, combined with WP_DEBUG_DISPLAY, is how you get the file and line number back. If that generic page is what brought you here, the critical error page walkthrough covers the triage path.

Step-by-step

1. Back up wp-config.php before you touch it. A syntax error in this file takes the entire site down, including wp-admin, so make the rollback available before you need it.

cd /home/USER/public_html
cp -p wp-config.php wp-config.php.bak-$(date +%F)
ls -l wp-config.php*
-rw-r----- 1 user user 3421 Aug 18 09:12 wp-config.php
-rw-r----- 1 user user 3421 Aug 18 09:12 wp-config.php.bak-2026-08-18

2. Read what is set right now. Do not assume the file is the whole story — a must-use plugin or a host dropin can define these first.

wp config list
wp config get WP_DEBUG --type=constant
+--------------------+------------------------------+----------+
| key                | value                        | type     |
+--------------------+------------------------------+----------+
| DB_NAME            | siteprod                     | constant |
| DB_USER            | siteprod                     | constant |
| table_prefix       | wp_                          | variable |
| WP_DEBUG           |                              | constant |
+--------------------+------------------------------+----------+
false

The blank cell is not a missing value — it is false rendered into a table, which is why the second command is worth running.

wp config parses the file, so it tells you what wp-config.php says. To find out what the running site actually resolved to — after mu-plugins and dropins — ask WordPress itself:

wp eval 'var_dump( WP_DEBUG, WP_DEBUG_LOG, WP_DEBUG_DISPLAY, SCRIPT_DEBUG );'
bool(false)
bool(false)
bool(true)
bool(false)

Note WP_DEBUG_DISPLAY reporting true on a site with debugging off. That is the default, sitting there harmlessly — and it is exactly what bites the moment someone flips WP_DEBUG on.

3. Create the log destination outside the docroot. The point of the absolute-path form is that no URL can reach the file. Put it beside the account’s other logs, not under public_html.

mkdir -p /home/USER/logs
touch /home/USER/logs/wp-debug.log
chmod 640 /home/USER/logs/wp-debug.log
chown USER:USER /home/USER/logs/wp-debug.log
ls -ld /home/USER/logs /home/USER/logs/wp-debug.log
drwxr-x--- 2 user user 4096 Aug 18 09:20 /home/USER/logs
-rw-r----- 1 user user    0 Aug 18 09:20 /home/USER/logs/wp-debug.log

The owner must be the user PHP runs as. If PHP-FPM runs as www-data while the file is owned by user at mode 640, PHP cannot write and you get an empty log with no error anywhere.

4. Write the debug block above the wp-settings.php require. Open wp-config.php and place this immediately before the /* That's all, stop editing! */ marker. The environment gate means the same file can be deployed everywhere.

# Debug block - must sit ABOVE the wp-settings.php require at the end of this file.
define( 'WP_ENVIRONMENT_TYPE', getenv( 'WP_ENVIRONMENT_TYPE' ) ?: 'production' );

if ( 'production' === WP_ENVIRONMENT_TYPE ) {
	# Log everything, show nothing, keep the file out of the docroot.
	define( 'WP_DEBUG', true );
	define( 'WP_DEBUG_DISPLAY', false );
	define( 'WP_DEBUG_LOG', '/home/USER/logs/wp-debug.log' );
	@ini_set( 'display_errors', 0 );
} else {
	# Local and staging: be as loud as possible.
	define( 'WP_DEBUG', true );
	define( 'WP_DEBUG_DISPLAY', true );
	define( 'WP_DEBUG_LOG', true );
	define( 'SCRIPT_DEBUG', true );
}

WP_ENVIRONMENT_TYPE accepts exactly four values — local, development, staging and production — and anything else falls back to production, the fail-safe direction. Note that WordPress turns WP_DEBUG on by itself when the environment type is development and WP_DEBUG is undefined; defining it explicitly removes that surprise.

The @ini_set( 'display_errors', 0 ) line is not redundant with WP_DEBUG_DISPLAY. It closes the window before wp_debug_mode() runs, so an error raised inside wp-config.php itself, or in a dropin loaded earlier, still does not print. Once core takes over, WP_DEBUG_DISPLAY is what holds the setting down.

5. Or make the same change with WP-CLI. It inserts new constants above the “stop editing” anchor for you, which removes the ordering mistake entirely.

wp config set WP_DEBUG true --raw
wp config set WP_DEBUG_DISPLAY false --raw
wp config set WP_DEBUG_LOG /home/USER/logs/wp-debug.log
wp config get WP_DEBUG --type=constant
Success: Updated the constant 'WP_DEBUG' in the 'wp-config.php' file with the raw value 'true'.
Success: Updated the constant 'WP_DEBUG_DISPLAY' in the 'wp-config.php' file with the raw value 'false'.
Success: Updated the constant 'WP_DEBUG_LOG' in the 'wp-config.php' file with the value '/home/USER/logs/wp-debug.log'.
true

The full flag list for these subcommands is in the WP-CLI config command reference. --raw is the difference between the boolean true and the string 'true'. For WP_DEBUG the string is only truthy by accident — write it raw and it stays a boolean. The path, by contrast, must not be raw, because it needs its quotes.

6. Block wp-content/debug.log if it has to stay in the docroot. Some hosts give you nothing writable outside public_html. The file is then fetchable at https://example.com/wp-content/debug.log by anyone who guesses, and it holds full server paths, query fragments and occasionally credentials leaked by a careless plugin. Deny it explicitly.

On Apache or LiteSpeed, in wp-content/.htaccess:

<Files "debug.log">
    Require all denied
</Files>

On Nginx, in the server block:

location = /wp-content/debug.log {
    deny all;
}

This is a mitigation, not a fix. An absolute path outside the docroot is the fix.

7. Understand where the errors can end up. With the block in place there are still several files in play, and only two of them are yours.

Data flow showing a PHP error passing through wp_debug_mode and out to five destinations: the browser response body routed by WP_DEBUG_DISPLAY, wp-content/debug.log inside the docroot, a log file outside the docroot set by an absolute path, PHP's own error_log from php.ini when WP_DEBUG_LOG is false, and the host's web server log which WordPress never controls

The one to internalise is the fourth: when WP_DEBUG_LOG is false, core never calls ini_set('error_log', ...), so PHP keeps logging wherever php.ini or the FPM pool already pointed. The errors are not lost, they are elsewhere. Reading the WordPress error log covers finding that file and reading it.

8. Add rotation before you forget. Neither WordPress nor PHP rotates this file. One deprecation notice per page view on a busy site produces gigabytes, and on shared hosting you hit the disk or inode quota first. A logrotate snippet in /etc/logrotate.d/wp-debug:

/home/USER/logs/wp-debug.log {
    weekly
    rotate 4
    missingok
    notifempty
    compress
    copytruncate
    su USER USER
}

copytruncate is the conservative choice here: it keeps the same inode, so it does not matter whether PHP is holding the file handle open between requests.

Validate it works

Reload PHP so the new wp-config.php is read — under FPM with OPcache an existing worker may serve the old file for a while — then confirm the resolved values, not the file contents:

wp eval 'var_dump( WP_DEBUG, WP_DEBUG_LOG, WP_DEBUG_DISPLAY, ini_get( "display_errors" ), ini_get( "error_log" ) );'
bool(true)
string(28) "/home/USER/logs/wp-debug.log"
bool(false)
string(1) "0"
string(28) "/home/USER/logs/wp-debug.log"

ini_get('error_log') echoing your path is the proof core actually applied it. Now write one harmless entry and watch it land:

wp eval 'error_log( "wp-debug check " . gmdate( "c" ) );'
tail -n 2 /home/USER/logs/wp-debug.log
[18-Aug-2026 13:40:02 UTC] wp-debug check 2026-08-18T13:40:02+00:00

Then confirm nothing reaches the browser. Fetch the home page and grep the body for the shapes PHP notices take:

curl -sS https://example.com/ | grep -icE "Warning:|Notice:|Deprecated:|Fatal error:"
0

A 0 is what you want. Anything higher means display_errors is switched back on after WordPress ran — usually by a plugin, or by an .user.ini PHP re-reads. Finally, if you enabled SCRIPT_DEBUG, check the asset that actually changes:

curl -sS https://example.com/ | grep -o "jquery[^\"']*\.js"
jquery.min.js

With SCRIPT_DEBUG off you get .min.js; with it on, jquery.js. If the filename does not change, the constant is not reaching the script loader.

Troubleshooting

The constants are set and the log stays empty. Four causes, in this order. One: the definitions sit below the wp-settings.php require — grep -n "wp-settings\|WP_DEBUG" wp-config.php and compare line numbers. Two: the file is not writable by the PHP user, whoever that is — sudo -u www-data test -w /home/USER/logs/wp-debug.log && echo writable. Three: the directory does not exist, and PHP will not create it. Four: ini_get('error_log') does not match your path, meaning something reset it after core ran.

It works locally and nothing changes on the host. Managed WordPress platforms often define these constants in a dropin or must-use plugin, or set php_admin_value[display_errors] in the FPM pool, which ini_set() cannot override by design. Compare wp config get WP_DEBUG --type=constant against wp eval 'var_dump( WP_DEBUG );' — when the file and the runtime disagree, look in wp-content/mu-plugins/ and ask the host what they enforce.

Notices are still printing on the page. Check that you set WP_DEBUG_DISPLAY to false and not to null; null deliberately tells WordPress not to touch display_errors, so php.ini wins. Then check for a plugin calling ini_set('display_errors', 1) later in the request: grep -rn "display_errors" wp-content/plugins/ wp-content/mu-plugins/ usually finds it in one line.

debug.log has filled the disk. Read it before you clear it, then truncate rather than delete so PHP does not keep writing into an unlinked file it still holds open: : > wp-content/debug.log. Add the rotation snippet above. A log growing that fast is one plugin emitting the same notice on every request, and that is the actual bug.

The log is full of the same deprecation over and over. WP_DEBUG makes _deprecated_function() and _deprecated_argument() fire real E_USER_DEPRECATED errors, which is the point, but an old theme calling one removed function in a loop buries everything else. Fix the caller — filtering the notices away with the deprecated_function_trigger_error hook hides the signal you turned the constant on to see.

When this is the wrong approach

WP_DEBUG is a PHP error switch and nothing more. It will not show you a slow query, a memory ceiling being hit, or a request that dies before PHP produces output. If the page returns nothing at all, or a 500 with an empty body, the process died before the error handler ran — check the server’s own error log instead, because debug.log will have nothing in it.

Leaving WP_DEBUG on permanently has a cost too. Raising error_reporting to E_ALL means every notice from every plugin is formatted and written on every request, which is measurable I/O when one plugin is chatty. On a high-traffic site the honest pattern is to switch it on for a defined window while you chase a fault, then off again; the always-on block above suits a normal site whose log stays quiet.

And if the problem is front-end behaviour rather than PHP, SCRIPT_DEBUG is the only constant here that helps, and only for core’s own assets. A minified plugin bundle needs that plugin’s source maps, which no WordPress constant can produce.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.