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 / Flag | Description |
|---|---|
NAME | Name of the constant or variable to delete (e.g. WP_DEBUG) |
--type=constant | Target a PHP define() constant (default) |
--type=variable | Target a PHP $variable (e.g. $table_prefix) |
--config-file=PATH | Target 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
- Always verify first with
wp config listto confirm the key exists before deleting. - Never delete required keys —
DB_NAME,DB_USER,DB_PASSWORD,DB_HOST,$table_prefixare mandatory. - Use in deployment pipelines to strip dev-only constants before production promotion.
- Combine with
wp config setto replace rather than just delete when rotating values.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Error: The constant is not defined | Key name mismatch or wrong type | Double-check name with wp config list; try --type=variable |
| Site breaks after delete | Deleted a required constant | Restore using wp config set immediately |
| Permission denied | WP-CLI can't write to wp-config.php | Fix 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
wp config list— verify the current state of your config.wp config set— add or replace constants.wp config get— retrieve a single value before deleting.