Skip to main content

wp config delete

Overview

Remove a specific constant or variable from wp-config.php programmatically. Useful for cleaning up debug flags before going to production, or rotating security-sensitive constants.

What It Does

wp config delete removes a named PHP constant or variable from wp-config.php. It targets the exact define or variable declaration by name, leaving all other configuration intact.

Syntax

wp config delete <name> [--type=<type>] [--config-file=<path>]

Arguments & Options

Argument / FlagDescription
NAMEName of the constant or variable to delete (e.g. WP_DEBUG)
--type=constantTarget a PHP define() constant (default)
--type=variableTarget a PHP $variable (e.g. $table_prefix)
--config-file=PATHTarget a config file at a specific path

Basic Usage

Delete a constant

wp config delete WP_DEBUG

Delete a variable

wp config delete table_prefix --type=variable
Do not delete required variables

$table_prefix and database credential constants are required for WordPress to function. Deleting them will break the site.

Expected Output

Success: Deleted the constant 'WP_DEBUG' from the 'wp-config.php' file.

If the constant doesn't exist:

Error: The constant 'WP_DEBUG' is not defined in the 'wp-config.php' file.

Real-World Scenarios

Scenario 1: Remove debug constants before launching to production

wp config delete WP_DEBUG
wp config delete WP_DEBUG_LOG
wp config delete WP_DEBUG_DISPLAY
wp config delete SCRIPT_DEBUG

Scenario 2: Remove a staging-only constant

wp config delete DISABLE_WP_CRON

Scenario 3: Verify deletion

wp config delete WP_DEBUG
wp config list | grep WP_DEBUG
# No output means it was removed successfully

Best Practices

  1. Always verify first with wp config list to confirm the key exists before deleting.
  2. Never delete required keysDB_NAME, DB_USER, DB_PASSWORD, DB_HOST, $table_prefix are mandatory.
  3. Use in deployment pipelines to strip dev-only constants before production promotion.
  4. Combine with wp config set to replace rather than just delete when rotating values.

Troubleshooting

ProblemCauseFix
Error: The constant is not definedKey name mismatch or wrong typeDouble-check name with wp config list; try --type=variable
Site breaks after deleteDeleted a required constantRestore using wp config set immediately
Permission deniedWP-CLI can't write to wp-config.phpFix file ownership (chown www-data:www-data wp-config.php)

Quick Reference

wp config delete WP_DEBUG                      # Delete a constant
wp config delete table_prefix --type=variable # Delete a variable
wp config list # Verify the deletion

Next Steps