wp cli alias
Overview
WP-CLI aliases are named shortcuts defined in wp-cli.yml or ~/.wp-cli/config.yml that point to a WordPress installation — local path, remote SSH, or multisite URL. They let you manage any number of environments with a single consistent command interface.
What It Does
wp cli alias provides subcommands to list, get, add, update, and delete aliases programmatically — without editing YAML files manually.
Subcommands
| Subcommand | Description |
|---|---|
wp cli alias list | List all defined aliases |
wp cli alias get ALIAS | Show configuration for a specific alias |
wp cli alias add ALIAS | Define a new alias |
wp cli alias update ALIAS | Update an existing alias |
wp cli alias delete ALIAS | Remove an alias |
Syntax
wp cli alias <subcommand> [OPTIONS]
Where Aliases Are Stored
| File | Scope |
|---|---|
~/.wp-cli/config.yml | Global — applies to all projects |
wp-cli.yml in WP root | Project-level — applies only to that install |
Basic Usage
List all aliases
wp cli alias list
Output:
@production
@staging
@local
@all
Get details of an alias
wp cli alias get @production
Output:
@production:
ssh: deploy@prod.example.com/var/www/wordpress
Alias Structure in wp-cli.yml
# ~/.wp-cli/config.yml
@production:
ssh: deploy@prod.example.com/var/www/html
path: /var/www/html
@staging:
ssh: deploy@staging.example.com/var/www/html
@local:
path: /var/www/local-dev
@docker:
ssh: docker:wordpress_app/var/www/html
Using Aliases
# Run a command on the production server via SSH
wp @production cache flush
# Check the WordPress version on staging
wp @staging core version
# List plugins on local
wp @local plugin list --status=active
Real-World Scenarios
Scenario 1: Sync production to staging
#!/bin/bash
# sync-prod-to-staging.sh
echo "Exporting production database..."
wp @production db export /tmp/prod-$(date +%Y%m%d).sql
echo "Transferring to staging server..."
scp deploy@prod.example.com:/tmp/prod-*.sql deploy@staging.example.com:/tmp/
echo "Importing on staging..."
wp @staging db import /tmp/prod-$(date +%Y%m%d).sql
echo "Replacing production URLs with staging..."
wp @staging search-replace 'https://prod.example.com' 'https://staging.example.com' --skip-columns=guid
echo "Flushing staging cache..."
wp @staging cache flush
echo "Done!"
Scenario 2: Fleet-wide plugin audit
for env in @production @staging @local; do
echo "=== $env ==="
wp "$env" plugin list --update=available --format=count | xargs echo " Plugins needing update:"
done
Scenario 3: Deploy to all environments
for env in @staging @production; do
wp "$env" maintenance-mode activate
wp "$env" plugin update --all
wp "$env" cache flush
wp "$env" maintenance-mode deactivate
echo "Updated: $env"
done
Group Aliases (Targeting Multiple Sites at Once)
# wp-cli.yml
@all:
- @production
- @staging
- @local
# Run on all environments simultaneously
wp @all core version
wp @all cache flush
Docker Container Aliases
@wordpress-docker:
ssh: docker:my_wordpress_container/var/www/html
wp @wordpress-docker plugin list
Best Practices
- Store aliases in
~/.wp-cli/config.ymlglobally so they work across all projects. - Store project aliases in
wp-cli.ymlin the repo so teammates share them. - Use group aliases (
@all) for bulk operations across environments. - Always test commands on
@stagingbefore running on@production. - Use SSH key authentication for remote aliases — no password prompts in automation.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Error: Unknown alias | Alias not in config file | Run wp cli alias list to verify |
| SSH connection refused | Wrong SSH address or port | Test with ssh user@host directly |
| Command runs on wrong site | Wrong --path in alias definition | Verify with wp @alias option get siteurl |
Quick Reference
wp cli alias list # List all aliases
wp cli alias get @production # Show alias config
wp @production cache flush # Use alias
wp @staging core version # Target staging
Next Steps
wp config create— create awp-config.phpfrom the CLI.wp config get— read values from the config file.- Output Formats — combine with format flags for scripting.