Home / Software / WordPress / How to Manage Your WordPress Site Using WP-CLI
A screen full of code.

How to Manage Your WordPress Site Using WP-CLI

WordPress is a fairly easy platform to pick up, yet difficult to master. If you want your site to succeed, you’ll need to juggle a lot of responsibilities, such as creating new content, keeping things updated, and managing your themes and plugins. It’s a lot of work, so anything that can help you do these tasks more efficiently should be welcome.

That’s where the WordPress Command Line (WP-CLI) comes in. This tool enables you to handle all your managerial duties from the command line using a few keywords. Even if you’re not a developer, this approach can save you a lot of time. For example, you can install new plugins in a matter of seconds without accessing your dashboard.

In this article, we’re going to talk more about what WP-CLI does and how it works. Then, we’ll teach you how to set it up and use it in four simple steps. Let’s get to work!

An Introduction to WP-CLI

The WP-CLI homepage.

WP-CLI is a tool that enables you to control your WordPress setup through a command line interface. Once you’ve set it up, you can manage most of your day-to-day tasks using simple commands such as wp core update, which updates your version of WordPress to the latest one – without you having to access your dashboard.

These days, most of you probably don’t use your Operating System’s (OS) command line tools at all. However, doing so isn’t complicated. You simply have to memorize a few commands or keep WP-CLI’s documentation handy, and you’ll be able to use the tool like a pro.

Key Features:

  • Manage your WordPress installation from the command line.
  • Install and activate any plugins and themes you want using the tool.
  • Update all your site’s elements (and WordPress core) to their latest versions.
  • Access WP-CLI using Secure Shell (SSH) access.

Price:

WP-CLI is 100% free and open-source.

How to Use WP-CLI to Manage Your WordPress Site (in 4 Steps)

Before we jump into the tutorial, it’s worth noting that not every hosting environment is capable of running WP-CLI. If you’re on a shared hosting plan, you likely won’t be able to use it, and we’ll discuss why during the first step.

Step 1: Install WP-CLI

To set up WP-CLI, you’ll need a hosting environment that meets the following criteria:

  1. A Unix-based environment, although there’s limited support for Windows servers.
  2. PHP 5.3.29 or a more recent version.
  3. WordPress 3.7 or a newer release.
  4. SSH access to your server.

The first three criteria are easy enough to meet, and most web hosts are up to spec. However, not every provider grants its users SSH access, and chances are yours won’t either unless you’re running a Virtual Private Server (VPS). Keep in mind that WordPress-friendly web hosts are more likely to support the use of WP-CLI. For example, we enable you to use the tool on our WordPress plans.

Assuming you have SSH access, you’ll need to use either your command line (if you’re on a Unix system) or a tool such as Putty to connect to your server. Then, run the following command:

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

This will download the files you need to install WP-CLI to your server. Now, let’s turn that .phar file into an executable with a second command:

chmod +x wp-cli.phar

Finally, we’re going to use the third command to move our executable to a new folder called wp:

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

Now we can call up WP-CLI from our command line by typing mv. For example, typing wp -info should tell you which version of WP-CLI you’re running, and it’s a good way to confirm if your installation is ready to go.

Step 2: Update WordPress’ Core

If you made it to this step, the hardest part is already done. You simply need to learn some basic commands to start using WP-CLI to make your life easier. The first thing you should do is check if you’re running the latest version of WordPress core. To do that, type the following into your command line:

wp core check-update

If there’s a new version available, WP-CLI will notify you, and you’ll be able to install it using this command:

wp core update

Now WP-CLI will work its magic, and your site will be running the latest version of WordPress. It’s that simple.

Step 3: Manage Your Plugins and Themes

Installing a plugin or a theme using your dashboard takes multiple steps. You have to go to their respective tabs, find the right plugin or theme (or upload them), click a couple of buttons, wait for the process to end, and activate them. However, when you’re using WP-CLI, all it takes is a single command to install and activate. For example:

wp theme install twentyseventeen --activate

You can separate the above into two commands, but it’s more efficient to do it in one fell swoop. If you want to install a plugin, replace the words theme and twentyseventeen. Let’s use another example to illustrate:

wp plugin install hello-dolly --activate

The terms we use to identify both plugins and themes are called ‘slugs’. For example, twentyseventeen is the slug for the WordPress Twenty Seventeen theme. To find out the slug for any plugin or theme, you’ll need to use the WP-CLI search command, like this:

wp theme search twenty seventeen

In this case, the query should return a list including the Twenty Seventeen theme and its corresponding slug. As usual, you can replace the theme parameter with plugin if you need to. As far as updating themes and plugins, you can do it with this interchangeable command:

wp theme update --all

That’s all you need to know to get started managing your plugins and themes using WP-CLI, but the tool offers many more parameters you can use. Check out its documentation to find out more about them.

Step 4: Create New Posts

Finally, all that’s left for now is to create your first post using WP-CLI. As you can imagine, this can be done using a single command:

wp post create --post_title='My test post'

In this case, the post_title parameter enables you to set a title for your post right away. Afterward, WP-CLI will return a success message indicating the ID of your post (such as Success: Created post 1900).

To edit your post’s content, you’ll need to use the following command:

wp post edit 1900

This will automatically launch your system’s default editor. Depending on your OS, using these text editors can be complicated, so if you’re working on an elaborate post, you might want to use the WordPress dashboard to polish things up.

Conclusion

Running a WordPress website can be a lot of work, but there’s no reason why you can’t find ways to tackle it more efficiently. For example, using the command line can save you time over the long run by enabling you to handle repetitive tasks with a few keyboard strokes. Plus, there’s plenty more you can do with WP-CLI if you take the time to read its full documentation.

Here’s what you need to do to get started using WP-CLI:

  1. Install the tool.
  2. Update WordPress’ core.
  3. Manage your plugins and themes.
  4. Create new posts.

Do you have any questions about how to manage your WordPress site using WP-CLI? Ask away in the comments section below!

Image credit: Pixabay.

About Brad Litwin

Brad Litwin is the Marketing Manager for A2 Hosting. He has been with the company since 2007. His specialties include affiliate marketing, content writing and SEO. In his spare time he enjoys running and reading.

Check Also

A loading dock.

How to Migrate Your WordPress.com Website to a Self-Hosted Setup

WordPress.com is a solid platform for people who want to get into blogging. However, it …