Skip to main content

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

FlagDescription
NAMEConstant or variable name (e.g. DB_NAME, table_prefix)
--constant=NAMEExplicitly target a PHP define() constant
--global=NAMEExplicitly target a PHP global variable
--type=TYPEconstant or variable
--format=FORMATtable, 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

ConstantDescription
DB_NAMEDatabase name
DB_USERDatabase username
DB_HOSTDatabase host
DB_CHARSETDatabase charset
table_prefixWordPress table prefix
WP_DEBUGDebug mode enabled
WP_DEBUG_LOGLog debug to file
DISALLOW_FILE_EDITDisable theme/plugin editor
FORCE_SSL_ADMINForce SSL on wp-admin
WP_MEMORY_LIMITPHP 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

  1. Use wp config get DB_NAME instead of parsing wp-config.php with grep in scripts — safer and more reliable.
  2. Export to JSON for full config audits: wp config get --format=json.
  3. Never log credentials — pipe output thoughtfully and avoid writing DB_PASS to insecure log files.

Troubleshooting

ProblemCauseFix
Error: Constant or variable not foundWrong name or not definedRun wp config get --format=table to see all defined values
Returns empty stringConstant defined but emptyThis is the actual value — the constant exists but is empty
Error: wp-config.php not foundWrong working directoryPass --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