A Complete Beginner’s Guide to WP-CLI

The WordPress Command Line Interface or more popularly known as the WP-CLI, is an alternative interface to WordPress’ administrative, management and development features through the command line through your terminal. The easiest way to put this across would be to imagine your WP-Admin interface broken down into a set of terminal commands. Of course, there is a lot more to this, else why would you be using it?

WP-CLI has mostly been an advanced feature primarily used by developers and system administrators, over this course we will try to break it down to a beginner’s level so that you can also get started with WP-CLI.

Throughout this article, we will assume that your WordPress is hosted on a server or a hosting account and not locally in your computer.

So the first question is, how do I get access to the WP-CLI?

If you are on a shared or WordPress hosting environment that does not offer your root access to the server, you would need to make sure that your host includes WP-CLI else you would not be able to install or use WP-CLI. Our partner and supporter Host4Geeks includes WP-CLI with their WordPress hosting plans . If you are on a VPS or a Dedicated server or basically any environment that you have root access to, follow the instructions below to install WP-CLI.

Installing WP-CLI:

Login to your server via SSH and ensure you have root access:

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

You need fileake this file executable and move it to your /bin directly so that it can be run directly from your command line:

chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp

To check if WP-CLI is installed correctly, run:

wp --info

You should see an output such as:

PHP binary: /usr/bin/php
PHP version: 7.1
php.ini used: /etc/php.ini
WP-CLI root dir: phar://wp-cli.phar
WP-CLI global config:
WP-CLI project config:
WP-CLI version: x.xx.xx

If everything works as above, congratulations you have successfully installed WP-CLI on your server.

Now that we have successfully installed and verified that WP-CLI is installed and working, we will go ahead and perform some basic operations using WP-CLI.

We will perform the following operations:

Updating WordPress Core

To update the WordPress Core you simply run:

wp core update

Yes, that’s all it takes. Now if you have multiple WordPress installations spread across the server, updating all of them takes a little bit of shell or bash scripting combined with the above command to install all WordPress installations in the entire server.

Listing all themes

wp theme list

You can see the name of the themes installed in your WordPress along with their respective version numbers and active or inactive status.

Listing all plugins

wp plugin list

You can see the name of the plugins installed in your WordPress along with their respective version numbers and active or inactive status.

Updating all plugins

wp plugin update --all

Updating a specific plugin

wp plugin update <plugin_name>

Activating and Deactivating a specific plugin

wp plugin activate <slug>
wp plugin deactivate <slug>

Commands for WP-CLI are quite simple and easily understandable, you can type in:

wp help

The real power of WP-CLI can be harnessed by a system administrator when combining it with some basic shell or bash scripting.

A very good and comprehensive reference point for WP-CLI is the quick start guide available here.