WordPress CLI Getting Started banner
>_

WordPress CLI
Getting Started

Manage WordPress sites faster from the command line

W

WordPress CLI, usually called WP-CLI, is the official command line tool for managing WordPress sites. It lets you update core, install plugins, manage users, check settings, export databases and run maintenance tasks from your terminal.

If you manage WordPress sites, WP-CLI can save hours every month. It is especially useful when wp-admin is slow, inaccessible, or when you need to repeat the same task across multiple sites.

1. What is WP-CLI?

WP-CLI is a set of command line tools that extends WordPress. Instead of clicking through the dashboard, you can run simple commands to get things done.

It is fast, scriptable and useful for developers, system admins, hosting support teams and site managers.

Most commands begin with wp:

wp core version
wp plugin list
wp user list
$ wp --info

OS:             Linux 6.2.0 x86_64
Shell:          /bin/bash
PHP binary:     /usr/bin/php
PHP version:    8.2.12
php.ini used:   /etc/php/8.2/cli/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql Ver 8.0.36
WP-CLI root dir: phar://wp-cli.phar
WP-CLI version: 2.10.0

2. Is WP-CLI installed?

$ wp --version
WP-CLI 2.10.0

Tip

If you see a version number, you are good to go. If not, ask your host to install it or follow the official installation guide:

https://wp-cli.org/#installing

3. Navigate to your WordPress site

Move into your WordPress site directory. This is the folder where wp-config.php is located.

$ cd /home/user/public_html/your-site
$ ls

wp-admin            wp-content          wp-includes
wp-json             wp-config.php       wp-load.php
wp-blog-header.php  wp-cron.php         wp-login.php
wp-comments-post.php wp-links-opml.php  wp-mail.php
index.php           license.txt         readme.html
robots.txt

Tip

Most WP-CLI commands must be run from inside your WordPress root directory. If you see This does not seem to be a WordPress installation, you are probably in the wrong folder.

4. Basic commands to get started

These are the WP-CLI commands you will use all the time.

$ wp core version
6.5.2

Check WordPress version

Displays the currently installed WordPress version.

$ wp core update
Success: WordPress updated to 6.5.3.

Update WordPress core

Updates WordPress to the latest available version. Take a backup first on production sites.

$ wp plugin list

+----------------+----------+-----------+
| name           | status   | update    |
+----------------+----------+-----------+
| akismet        | active   | none      |
| contact-form-7 | active   | none      |
| yoast-seo      | active   | available |
+----------------+----------+-----------+

List installed plugins

Shows all installed plugins, whether they are active, and if updates are available.

$ wp plugin update --all
Success: All plugins updated.

Update all plugins

Updates all plugins to their latest versions. Best used after a backup or on staging first.

$ wp theme list

+-----------------+----------+-----------+
| name            | status   | update    |
+-----------------+----------+-----------+
| twentytwentyfour| active   | none      |
| astra           | inactive | available |
+-----------------+----------+-----------+

List installed themes

Shows installed themes, the active theme, and available theme updates.

5. Check site URLs

WP-CLI is very useful when troubleshooting domain changes, migrations and redirect issues.

$ wp option get home
https://example.com

$ wp option get siteurl
https://example.com

If these values are wrong, WordPress may redirect to the wrong domain or load assets incorrectly.

6. Manage users

You can list users, check roles and reset passwords from the command line.

$ wp user list

+----+------------+--------------+-------------------+---------------+
| ID | user_login | display_name | user_email        | roles         |
+----+------------+--------------+-------------------+---------------+
| 1  | admin      | Site Admin   | admin@example.com | administrator |
| 2  | editor     | Editor User  | editor@example.com| editor        |
+----+------------+--------------+-------------------+---------------+

Useful user commands:

wp user get admin
wp user reset-password 1
wp user create newuser user@example.com --role=editor

7. Flush cache

If the site uses object cache, WP-CLI can flush it quickly:

$ wp cache flush
Success: The cache was flushed.

This is useful after migrations, URL changes, plugin updates or strange cached behaviour.

8. Export the database before risky changes

Before updates, search-replace operations or major maintenance, export the database.

$ wp db export before-changes.sql
Success: Exported to 'before-changes.sql'.

This is a good habit. Future you will be smugly grateful.

Common WP-CLI mistakes

  • Running commands in the wrong folder: make sure wp-config.php is present.
  • Updating without backups: export the database first on important sites.
  • Using the wrong PHP version: check wp --info.
  • Forgetting file ownership: permission issues can stop commands working properly.
  • Running destructive commands too quickly: pause before deleting, replacing or updating.

FAQ

What is WP-CLI used for?

WP-CLI is used to manage WordPress from the command line. You can update WordPress, list plugins, manage users, export databases and run maintenance tasks.

How do I check if WP-CLI is installed?

wp --info

Where should I run WP-CLI commands?

Run WP-CLI commands from the WordPress root directory, where wp-config.php is located.

How do I list plugins with WP-CLI?

wp plugin list

How do I update all plugins?

wp plugin update --all

Is WP-CLI safe?

Yes, when used carefully. Always check the directory and take backups before risky updates or database operations.

Practical workflow

A safe WP-CLI maintenance flow

# Confirm WP-CLI can see the site
wp core version

# Check current plugin status
wp plugin list

# Check available updates
wp core check-update
wp plugin list --update=available
wp theme list --update=available

# Take a database export before bigger changes
wp db export before-maintenance.sql

# Run updates when you are ready
wp plugin update --all
wp theme update --all

Related: WP-CLI Search Replace Guide, MySQL CLI for WordPress and WP-CLI Getting Started.

FAQ

Frequently Asked Questions

What is WP-CLI used for?

WP-CLI is used to manage WordPress from the command line, including plugins, themes, users, updates, database exports and search-replace tasks.

How do I check the WordPress version with WP-CLI?

Run wp core version from the WordPress document root.

How do I list WordPress plugins with WP-CLI?

Run wp plugin list to show installed plugins and their status.

Should I export the database before WP-CLI changes?

Yes. Export the database before updates or search-replace operations so you can roll back if needed.

$ practise_next --topic wp-cli

Practise this next

Turn the guide into practice with a related quiz, builder, cheat sheet or learning path.