wp config get
Overview
Read any constant or variable defined in wp-config.php from the command line — without opening the file. Safe for scripts, audits, and environment verification.
What It Does
wp config get parses wp-config.php and returns the value of the specified constant or variable. It never executes the config file — it statically reads the values. This makes it safe even when the database is unreachable.
Syntax
wp config get [<name>] [OPTIONS]
Arguments & Options
| Flag | Description |
|---|---|
NAME | Constant or variable name (e.g. DB_NAME, table_prefix) |
--constant=NAME | Explicitly target a PHP define() constant |
--global=NAME | Explicitly target a PHP global variable |
--type=TYPE | constant or variable |
--format=FORMAT | table, json, yaml, csv |
Basic Usage
Get a single constant
wp config get DB_NAME
Output:
wordpress_production
Get the table prefix
wp config get table_prefix
List all constants and variables
wp config get --format=table
Output (truncated):
+------------------+-------------------------------+-----------+
| name | value | type |
+------------------+-------------------------------+-----------+
| DB_HOST | localhost | constant |
| DB_NAME | wordpress_production | constant |
| DB_USER | wp_user | constant |
| WP_DEBUG | | constant |
| table_prefix | wp_ | variable |
+------------------+-------------------------------+-----------+
Common Config Keys
| Constant | Description |
|---|---|
DB_NAME | Database name |
DB_USER | Database username |
DB_HOST | Database host |
DB_CHARSET | Database charset |
table_prefix | WordPress table prefix |
WP_DEBUG | Debug mode enabled |
WP_DEBUG_LOG | Log debug to file |
DISALLOW_FILE_EDIT | Disable theme/plugin editor |
FORCE_SSL_ADMIN | Force SSL on wp-admin |
WP_MEMORY_LIMIT | PHP memory limit override |
Real-World Scenarios
Scenario 1: Verify DB connection settings before migrate
echo "DB Host: $(wp config get DB_HOST)"
echo "DB Name: $(wp config get DB_NAME)"
echo "DB User: $(wp config get DB_USER)"
echo "Prefix: $(wp config get table_prefix)"
Scenario 2: Check debug status in CI
DEBUG=$(wp config get WP_DEBUG 2>/dev/null || echo "false")
if [[ "$DEBUG" == "true" || "$DEBUG" == "1" ]]; then
echo "WARNING: WP_DEBUG is enabled on this environment!"
fi
Scenario 3: Export all config to JSON for audit
wp config get --format=json > wp-config-audit-$(date +%Y%m%d).json
Scenario 4: Use DB_NAME in a backup script
DB_NAME=$(wp config get DB_NAME)
DB_USER=$(wp config get DB_USER)
BACKUP_FILE="/backups/${DB_NAME}-$(date +%Y%m%d).sql"
wp db export "$BACKUP_FILE"
echo "Backup saved to: $BACKUP_FILE"
Best Practices
- Use
wp config get DB_NAMEinstead of parsingwp-config.phpwithgrepin scripts — safer and more reliable. - Export to JSON for full config audits:
wp config get --format=json. - Never log credentials — pipe output thoughtfully and avoid writing
DB_PASSto insecure log files.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Error: Constant or variable not found | Wrong name or not defined | Run wp config get --format=table to see all defined values |
| Returns empty string | Constant defined but empty | This is the actual value — the constant exists but is empty |
Error: wp-config.php not found | Wrong working directory | Pass --path=/var/www/wordpress |
Quick Reference
wp config get DB_NAME # Get a constant
wp config get table_prefix # Get a variable
wp config get --format=table # List all constants
wp config get --format=json # JSON output
Next Steps
wp config set— update values in the config.wp config create— create a newwp-config.php.wp db export— use config values to back up the database.