What Is the WordPress CLI (And How Can You Use It)?

  by Jason Cosper
What Is the WordPress CLI (And How Can You Use It)? thumbnail

As you get more comfortable developing WordPress, you’ll want some tools that will help you complete your tasks quickly and efficiently. The WordPress admin dashboard is intuitive and comprehensive, but it can also be time-consuming to navigate.

What if you want to manage your site more directly, with just a few easy commands? This is where the WordPress Command Line Interface (WP-CLI) comes in handy.

The WP-CLI is a tool that enables you to interact with your WordPress site directly by using commands in a text-based interface. It’s also very comprehensive, with a wide variety of potential commands. Almost anything you can do on the back end of your site, you can do much faster using the WP-CLI.

What is the WordPress CLI (WP-CLI)?

The WP-CLI is a tool that enables you to interact with your WordPress site directly by using commands in a text-based interface. Instead of clicking through admin menus, you type short commands to install WordPress, manage themes, plugins, and users, and update the software, and you can chain those commands into scripts that automate it all.

WordPress CLI

As the name suggests, this tool enables you to perform administrative tasks on your WordPress site using a command line. With this method, you can complete a task by simply typing in a line of code and hitting Enter.

Like most WordPress users, you’re probably very familiar with the WordPress admin area. It works well, but it’s not the only option for managing your site. Having a graphical interface is certainly preferable for some users. However, it does mean time spent navigating menus and waiting for pages to load: installing and activating a plugin through the dashboard takes a login, a couple of screens, and several clicks, while the WP-CLI does it in one typed line (wp plugin install user-switching –activate, for example).

The beauty of the WP-CLI is that it gives you direct control over your site. Most of what you can do in the WordPress admin dashboard, you can do with the WP-CLI, plus some things the admin can’t do at all: a single command, wp transient delete –all, clears every leftover transient from your database. It’s not nearly as complicated as you may fear, and there are plenty of resources available if you want to learn more about it.

To use the WP-CLI, you’ll need to install it on your WordPress site. Let’s look at this process in more detail now.

How to install WP-CLI on your WordPress website

If your site is hosted with DreamHost, it will already have the WP-CLI installed. If you need to, however, you can also install this tool manually.

You’ll first need to make sure that your environment is compatible, meaning that it conforms to the following specifications:

  • A UNIX-like environment (macOS, Linux, FreeBSD, Cygwin)
  • PHP 7.2.24 or later
  • WordPress 4.9 or later (versions older than the latest WordPress release may have degraded functionality)

That’s the whole list — per the official handbook, WP-CLI has no additional requirements beyond those of WordPress itself. The current stable release is WP-CLI 2.12.0 (May 2025).

That first point might be a problem for some users. The WP-CLI is made with UNIX-like environments in mind and has limited support for Windows. The simplest fix is the Windows Subsystem for Linux (WSL), which gives you a genuine Linux environment where the steps below work exactly as written. You can also install it natively on Windows, but expect some extra setup.

To install the WP-CLI in one of the environments on the above list, you’ll need to use Secure Shell (SSH) to download and configure the necessary files. First, you need to download the wp-cli.phar file to your root directory, using the following command:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

You should then check to make sure that the file is working, using another command:

php wp-cli.phar --info

Next, you’ll want to make the file executable, which will enable you to use the wp command. You’ll also want to move it to another directory. This final command will perform both tasks:

chmod +x wp-cli.phar

sudo mv wp-cli.phar /usr/local/bin/wp

No sudo? No problem. The file just needs to be executable and live somewhere in your PATH (/usr/local/bin is only an example). On shared hosting or any account without root access, create a bin folder in your home directory (mkdir -p ~/bin), move the file there as ~/bin/wp, and add that folder to your PATH in ~/.bash_profile. And if your host preinstalls WP-CLI (as DreamHost does), you can skip the download entirely: connect over SSH, cd into your site’s directory, and start running wp commands, or point any command at your install with the –path parameter.

With that, the WP-CLI should now be successfully installed. You can test it by running the command wp –info. If everything works, you’ll see information about your version of the WP-CLI displayed.

Two quick post-install upgrades will make daily use faster. First, tab completion: WP-CLI ships with a completion script for Bash and Z shell. Download wp-completion.bash, source it from your ~/.bash_profile, and your terminal will finish commands as you type. Second, a configuration file: WP-CLI reads defaults from a wp-cli.yml file, so you can set options like your WordPress path once instead of retyping them with every command.

That’s it! You’re now ready to use this tool to manage your site more efficiently. Before we move on, however, let’s run through some alternative methods of installation.

Get Content Delivered Straight to Your Inbox

Subscribe now to receive all the latest updates, delivered directly to your inbox.

Alternative ways to install the WP-CLI

As we alluded to earlier, there are actually several methods to install the WP-CLI. We won’t detail all of them in this article. However, we’ll list them out briefly and link to more information on each, so you can choose the technique that best suits your needs.

You can use the following tools to install the WP-CLI on your site:

Finally, you may want to get involved in developing the WP-CLI yourself. You can easily get involved with its development by using the Git installation instructions.

How to use WP-CLI: 7 essential commands

WP-CLI gives you direct command-line access to most WordPress administration tasks, plus some operations the dashboard doesn’t offer. There are dozens of commands you can use to manage nearly everything from comments to core updates. Plus, you can even create custom commands. (These days, an AI assistant can draft a WP-CLI one-liner or custom-command boilerplate for you, though you should review any generated command before running it on a live site.)

We’re now going to look at just a few of the standard commands available to you. This is to give you an idea of how you can use WP-CLI to manage your site before you dig deeper into the rabbit hole of possibilities.

1. Install and update WordPress with WP-CLI

The most fundamental task you can accomplish with the WP-CLI is to download and install WordPress on your site. The command for downloading WordPress is simply:

wp core download

This will download and extract WordPress in the current directory. You can also add additional parameters to refine the download further. For example, the locale parameter determines which translation of WordPress will be used. This command will download the Brazilian Portuguese version of WordPress:

wp core download --locale=pt_BR

Once downloaded, you can install WordPress using the install command. This command contains a number of parameters that configure the setup. Let’s take a look at an example:

wp core install --url=example.com --title=Example --admin_user=supervisor --admin_email=info@example.com --prompt=admin_password

As you can see, this is all fairly self-explanatory. Simply replace the example data in each parameter with your own values. One deliberate choice here: the –prompt=admin_password flag tells WP-CLI to ask for the admin password interactively instead of taking it in the command itself, which keeps it out of your shell history. (Omit the password entirely, and WP-CLI generates a random one.) To ensure that everything has worked as expected, you can use the following command to test the installation:

wp core version

This will return the version number of your installation, proving that WordPress has been successfully installed! Now you can make sure it’s updated with the following command:

wp core update

If a newer version of WordPress is available, it will be downloaded and installed automatically after you run this command.

2. Manage themes and plugins

There are many ways you can manage themes and plugins using the WP-CLI, so let’s look at some of the basic options now. First, you can use the list command to view a list of your themes or plugins. Using parameters, you can filter the display by items with a specific status (such as inactive) or a particular output format.

For example, if you want to list all inactive themes as a CSV list, you can use the following command:

wp theme list --status=inactive --format=csv

You can also install a plugin by specifying its slug in the plugin directory, providing the path to a local file, or entering the URL for an external file. In this example, we’re also going to activate the plugin at the same time:

wp plugin install ../my-plugin.zip --activate

It’s also easy to switch themes. On a single-site install, you can activate a theme with one command (the similar wp theme enable command applies only to multisite networks). In this example, we’re activating Twenty Twenty-Five, the current default theme:

wp theme activate twentytwentyfive

There’s also a command for deactivating a plugin. In our example, we’ll use this command to disable the Hello Dolly plugin. We’ll also uninstall the plugin at the same time:

wp plugin deactivate hello --uninstall

Finally, you can search the respective directories looking for a specific plugin or theme. For instance, let’s search for a theme containing the string “photo”. We’re also setting it to return three results instead of the default ten:

wp theme search photo --per-page=3

This will display the following table:

WordPress CLI query table

As we mentioned, this is only a small taste of how you can manage themes and plugins using the WP-CLI. Hopefully, you’re getting a sense of how useful this tool can be.

3. Create a child theme

By using the scaffold command, you can generate a child theme that includes the functions.php and style.css files. We recommend that you do this if you want to make changes to an existing theme. When you use a child theme, any customizations won’t be lost after new software updates.

To do this, you’ll simply need to specify the slug for the new child theme, and for the theme you’re using as the “parent.” In this example, we’re creating a child based on the Twenty Twenty-Five theme, and we’re giving it the slug twentytwentyfive-child:

wp scaffold child-theme twentytwentyfive-child --parent_theme=twentytwentyfive

If the process is successful, you’ll see a message that the child theme has been created. This will also include the path to its directory:

Success: Created '/var/www/example.com/public_html/wp-content/themes/twentytwentyfive-child'.

You’ll now find the child theme in the specified directory, ready to be edited!

4. Moderate comments

Moderating and managing comments is made a lot easier in the WP-CLI, which enables you to quickly create, delete, and edit them. There are many comment subcommands you can use, but let’s look at some of the most basic options.

First, you can add a new comment. The following command will add a comment to a post with the post ID of 20, and specifies the contents and author:

wp comment create --comment_post_ID=20 --comment_content="This is my comment" --comment_author="author-name"

Before you manage existing comments, it can be helpful to get a current list. You can do this with the list command, and the results can be filtered in multiple ways. For example, using this command will return a table containing the comment ID and author name for the three most recent approved comments (to list the comments on a specific post, use the –post_id parameter instead):

wp comment list --number=3 --status=approve --fields=ID,comment_author

This is what the resulting table will look like:

WordPress CLI query table

If you want to delete comments, you can do that by specifying the comment IDs individually, like this:

wp comment delete 64

You can also delete multiple comments by separating each ID with a space. In this example, we’re also using the force parameter, which permanently deletes comments instead of adding them to the trash bin:

wp comment delete 5 22 64 --force

One word of caution: –force and other destructive flags don’t ask twice. Before running bulk deletions on a live site, take a database backup with wp db export (covered next) or rehearse the operation on a staging copy first. With a little practice, you can work through your site’s comments very quickly using WP-CLI commands.

5. Back up and migrate your database

Now for the commands developers lean on most. The wp db export command dumps your database to a SQL file (your safety net before any risky change) and the first half of any migration:

wp db export

Run with no arguments, it creates a file named after your database plus the date and a random hash. Its counterpart, wp db import, loads a SQL file back into a site, so together the pair covers backups, restores, and site moves.

The other migration essential is wp search-replace, which searches every row in your database tables and swaps one string for another — the standard way to update URLs after moving a site to a new domain. Unlike a raw SQL query, it intelligently handles PHP serialized data. Rehearse the operation with the –dry-run flag first, which runs the whole search and shows a report without saving any changes:

wp search-replace 'http://example.test' 'https://example.com' --dry-run

Happy with the report? Run the same command again without –dry-run to apply it for real. (And yes: take a wp db export first.)

6. Manage users

The wp user command manages users along with their roles, capabilities, and meta. Creating a new author takes one line, and WP-CLI generates a password for the account and prints it in the output:

wp user create bob bob@example.com --role=author

Where wp user really shines is in bulk. wp user list shows every account at a glance, wp user import-csv creates users from a CSV file, and when someone leaves the team, you can delete their account and reassign their posts to a colleague in a single step:

wp user delete 123 --reassign=567

7. Update the WP-CLI

As with every aspect of WordPress, you should always make sure that the WP-CLI is up to date. Fortunately, this is very simple. All you need to do is run the following command:

wp cli update

If your version is the most recent available, you will get a message confirming this. However, if a new version can be downloaded, you’ll be prompted to accept the installation. If you select yes, the WP-CLI will be updated, and you’ll see a confirmation message with the new version number (2.12.0 is the current stable release, published in May 2025):

Success: Updated WP-CLI to 2.12.0

Whether you need sudo here depends on where the file lives: a root-owned /usr/local/bin/wp needs sudo wp cli update, while a phar in your own ~/bin updates with the plain command.

With that, you’ve updated your installation of the WP-CLI.

By now, you’re beginning to see what you can accomplish using this simple interface. There’s more to learn, but you should be proud of how far you’ve come already!

Automate WordPress tasks with WP-CLI

Here’s the real payoff: every WP-CLI command is scriptable. Anything you can type once, you can drop into a shell script and run on a schedule or as part of a deployment. That’s what separates the WP-CLI from being merely a faster admin dashboard.

A cron job is the simplest place to start. This crontab line moves into your site’s directory and takes a nightly database backup at 3 a.m.:

0 3 * * * cd ~/example.com && wp db export

The same idea scales up: a short bash script can chain any of the commands above across every site you manage, and a deploy script can run wp search-replace with –dry-run as a pre-flight check before changes go live. The official wp search-replace documentation even ends its examples with a ready-made bash script for swapping production URLs to development ones.

FAQs about WP-CLI

What is WP-CLI?

WP-CLI is the official command-line interface for WordPress. It lets you install WordPress, manage themes, plugins, users, and databases, and automate maintenance tasks by typing commands over SSH instead of clicking through the admin dashboard.

How do I access WP-CLI?

Connect to your server over SSH, then change into your WordPress site’s directory and run wp commands from there. If you’re outside the site directory, add the –path parameter to point WP-CLI at your WordPress files.

How do I install WP-CLI?

Download the wp-cli.phar file with curl, check it with php wp-cli.phar –info, make it executable with chmod +x, and move it into a directory on your PATH. Then run wp –info to confirm the installation.

Is WP-CLI preinstalled on DreamHost?

Yes. WP-CLI is installed on all DreamHost servers, so there’s nothing to set up. Connect over SSH, move into your site’s directory, and start running wp commands right away.

Does WP-CLI work on Windows?

Only partially. The officially supported environments are UNIX-like (macOS, Linux, FreeBSD, Cygwin), and native Windows support is limited. The Windows Subsystem for Linux (WSL) is the easiest route, since the standard Linux install steps work unchanged.

Work more efficiently with the WordPress CLI

Speed, accessibility, and efficiency are all traits that any smart developer looks for in their tools. The WP-CLI offers all of these and more while enabling you to manage your WordPress site remotely. Using the WP-CLI, you can perform most of the actions possible in the WordPress admin, just much more quickly (once you’ve had a bit of practice) — and you can script the routine ones so you don’t have to perform them at all.

Ad background image

Do More with DreamPress

Upgrade to DreamPress, DreamHost’s managed WordPress hosting, for fully managed performance, 1-click staging, free site migrations, daily backups, and 24/7 support from in-house WordPress experts.

Check Out Plans

Jason is DreamHost’s WordPress Product Advocate, based out of Bakersfield, CA. He is currently working on making our DreamPress product even better. In his free time, he likes to curl up on the couch and watch scary movies with his wife Sarah and three very small dogs. Follow him on Twitter.