Stop clicking through wp-admin for every small task. WP-CLI is a command-line tool that lets you manage WordPress sites faster — all from your terminal.
📌 Table of Contents
- Why WP-CLI?
- Problems It Solves
- Is It Good or Bad?
- Setup & Installation
- Must-Know Commands
- A Quick Real-World Use Case
- Your First Custom Script
- What's Next
Why WP-CLI?
Every WordPress developer knows the pain — update 12 plugins, flush cache, reset a password, run a search-replace after moving a site. Through the dashboard, that's 30+ clicks. With WP-CLI? A single line.
WP-CLI is the official command-line interface for WordPress. It lets you do everything you'd normally do in wp-admin, but from your terminal — faster, scriptable, and without touching a browser.
Problems It Solves
- Bulk operations — update all plugins/themes in one command
- Database search-replace — migrate sites without touching serialized data manually
- Locked out of wp-admin? — reset passwords or create admin users directly from CLI
- Repetitive setup tasks — stop doing the same 10 steps every new project
- Cron & scheduled tasks — trigger wp-cron reliably from server crontabs
Is It Good or Bad?
Honest answer — excellent for developers, a non-issue for anyone who'll never open a terminal.
| ✅ Good For | ⚠️ Watch Out For |
|---|---|
| Developer workflows | No undo on DB commands |
| Managing multiple sites | Wrong path → affects wrong site |
| Automating repetitive tasks | Needs SSH/terminal access |
| Faster deployments | Shared hosts may restrict it |
💡 Golden rule: Always test destructive commands on staging first. Power cuts both ways.
Setup & Installation
Linux / macOS
Step 1 — Download the Phar file:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Step 2 — Make it executable and move it globally:
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
Step 3 — Verify:
wp --info
You should see your OS, PHP version, and WP-CLI version. If you do — you're good to go.
Windows
Use WSL (recommended) or install via Composer:
composer global require wp-cli/wp-cli-bundle
💡 Using LocalWP, DevKinsta, or DDEV? WP-CLI is already bundled — no setup needed.
Must-Know Commands
Run all commands from your WordPress root directory.
| Command | What It Does |
|---|---|
wp core install |
Install WordPress in one shot |
wp plugin install <slug> --activate |
Install + activate a plugin from .org |
wp plugin update --all |
Update every plugin at once |
wp theme activate <slug> |
Switch active theme instantly |
wp user create |
Create a user with role and password |
wp search-replace 'old' 'new' |
Safe DB search-replace |
wp db export / import |
Backup or restore your database |
wp cache flush |
Clear the object cache |
wp option get/update |
Read or change wp_options values |
wp cron event run |
Manually trigger a WP-Cron event |
Full command reference → developer.wordpress.org/cli/commands
A Quick Real-World Use Case
🔁 Site Migration
Moving a site from local to staging? After transferring files and importing the DB, just run:
wp search-replace 'localhost' 'staging.example.com' --all-tables
That's it. Serialized data is handled safely — no broken arrays, no manual SQL editing. What used to take 20 minutes of careful find-and-replace now takes 3 seconds.
Your First Custom Script
Once you know the commands, the next step is combining them into a shell script. Here's a simple one that sets up a fresh WordPress install with your go-to plugins:
#!/bin/bash
# setup.sh — run after: wp core download && wp config create
# Install WordPress
wp core install \
--url=localhost \
--title="My Site" \
--admin_user=admin \
--admin_email=you@dev.com
# Install & activate your standard plugins
wp plugin install wordfence woocommerce yoast-seo --activate
# Clean permalink structure
wp rewrite structure '/%postname%/' --hard
echo "✅ Setup complete!"
Save it as setup.sh, make it executable with chmod +x setup.sh, and run it after every fresh install. Consistent environment, zero effort.
What's Next
You now have WP-CLI installed, know the essential commands, and have your first script running. That's a solid foundation.
In Part 2, we'll go deeper:
- Writing advanced custom PHP commands with
WP_CLI::add_command() - Using WP-CLI in CI/CD pipelines
- Managing remote WordPress sites
-
--dry-runpatterns so you never break production
Found this helpful? Drop a ❤️ and follow along for Part 2!
Top comments (0)