CentrioHost Blog

Stories and News from IT Industry, Reviews & Tips | Technology Blog


How to Manage Your WordPress Site Using WP-CLI

  • Category : WordPress
  • Posted on : Apr 22, 2017
  • Views : 1,541
  • By : Radcliff S.

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

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.

Subscribe Now

10,000 successful online businessmen like to have our content directly delivered to their inbox. Subscribe to our newsletter!

Archive Calendar

SatSunMonTueWedThuFri
 1
2345678
9101112131415
16171819202122
23242526272829
30 

Over 20000 Satisfied Customers!

  • web hosting reviewer
    Valerie Quinn
    CTO, Acteon Group

    Centriohost staff were fantastic, I had a concern with a domain and they got back to me very quickly and they helped me to resolve the issue! ~ . . . Read more

  • Joomla hosting reviewer
    Collin Bryan
    Photographer, Allister Freeman

    I'm using centrio for my portfolio since 2006. The transition was seamless, the support was immediate, and everything works perfectly. ~ . . . Read more

  • dedicated server reviewer
    Harry Collett
    Actor, A&J Artists

    Very easy to understand & use even though I am not very technologically minded. No complications whatsoever & I wouldn't hesitate to recommend it to all. ~ . . . Read more

  • vps web hosting reviewer
    Porfirio Santos
    Technician, Diageo PLC

    Centrio support team have been amazingly responsive and helpful to any of my queries, thank you so much to the Centriohost have been amazingly responsive and helpful to any of my queries 👍👍👍 ~ . . . Read more

  • wordpress hosting plans reviewer
    Catherine Auer
    Doctor, SmartClinics

    Anytime I've had a problem I can't solve, I've found Centriohost to be diligent and persistent. They simply won't let an issue go until the client is happy. ~ . . . Read more

  • reseller hosting reviewer
    Effectivo Social
    Freelancer, Fiverr

    Recommend their shared hosting for all my SME web design clients. Their cloud or VME offerings are too great to deal with. Pricing is perfect and suitable for all users (͠≖ ͜ʖ͠≖) 👌 ~ . . . Read more

Top