Home How to Use WP-CLI to Manage WordPress Websites Wordpress How to Use WP-CLI to Manage WordPress Websites How to Use WP-CLI to Manage WordPress Websites

How to Use WP-CLI to Manage WordPress Websites

April 11, 2021
How to Use WP-CLI to Manage WordPress Websites

WP-CLI is WordPress’s official command-line interface. It allows you to access the WordPress website, templates, and plugins directly from the terminal, which is also a more efficient way for intermediate to advanced WordPress developers to work on their pages.

In this article, you’ll learn how to get started with WP-CLI, as well as some of the most helpful commands you can use to make your life simpler and save time when working with WordPress.

How to Use WP-CLI to Manage WordPress Websites via @projects_engine. #projectsengine #wordpress #wpcli

Quick note: You don’t have to be a full-fledged WordPress developer to use and benefit from WP-CLI, but it is also a resource that is more suited to more experienced users with at least some technological experience, such as the ability to link to your server via SSH.

We suggest sticking with the WordPress dashboard and ignoring WP-CLI if you’re a complete novice. If you don’t know what a “command line” is, for example, you should generally skip WP-CLI.

What is the WP-CLI ( command-line interface )?

WP-CLI, or WordPress command-line interface, is a command-line interface that lets you access all facets of the WordPress platform from a command-line interface.

$ wp plugin install user-switching --activate
Installing User Switching (1.0.9)
Downloading installation package from https://downloads.wordpress.org/plugin/user-switching.1.0.9.zip...
Unpacking the package...
Installing the plugin...
Plugin installed successfully.
Activating 'user-switching'...
Plugin 'user-switching' activated.
Success: Installed 1 of 1 plugins.

Once you’ve established an SSH connection to your site, you can use simple commands to perform a variety of tasks, including the following:

  • WordPress, themes, and plugins activation, deactivation, and updates
  • Account creation and management, including password changes and other account details
  • Using the WordPress database to do a search and replace
  • Creating a sandbox site’s evaluation details
  • Editing or optimizing the servers, for example, by removing post-revisions
  • Making a child theme

What would you need in order to use WP-CLI?

You must have WP-CLI installed on your hosting server in order to use it (it does not come with WordPress by default).

WP-CLI is not a plugin that can be installed on your website. Instead, you’ll have to install it directly on your server, which is a little more difficult. Thankfully, most WordPress-focused hosts come with WP-CLI pre-installed.

If your host doesn’t already have it installed, you can install WP-CLI via SSH if you have enough access to your server. That depends on your hosting provider.

The below are the basic specifications for your server:

  • Ideally the latest version of WordPress, but it should be bigger than WordPress 3.7
  • PHP 7.2+ but it can not be lower than PHP 5.6
  • Installation on a Windows server is possible but complicated, we recommend a UNIX-like server environment

What’s the best way to get to the WP-CLI?

Once you’ve confirmed that WP-CLI is installed on your hosting, you can use SSH to bind to it, which you can do with Terminal on macOS and Linux or a program like PowerShell or PuTTY on Windows. If you’ve connected, you can use commands to interact with WP-CLI.

What will the WP-CLI be used for?

Let’s go over some of the various commands you can use to control the WordPress pages now that you know what the WordPress command-line interface is.

Use the wp core install command with additional parameters to manage the basic site specifics when creating a new WordPress installation.

wp core install --url=projectsengine.com --title=ProjectsEngine --
admin_user=admin --admin_password=password --
[email protected]

There are a variety of login and user-related commands in the WP-CLI. You can handle all facets of a user’s account, including password resets.

wp user update USERNAME --user_pass=PASSWORD
wp user create name [email protected] --role=author
wp user set-role USERNAME author

There are some plugin commands in WP-CLI that can be used to install, deactivate, or remove plugins. The main command is wp plugin, which is followed by the action you want to take and the plugin’s slug. Pretty easy, right?

You may also use the same commands to control the themes on your blog. The wp theme command is the starting point, and you can tweak it as desired. Here are some examples:

wp plugin install plugin-slug
wp theme install themename
wp theme activate themename

Plugins that work with the WP-CLI

The great thing about WP-CLI is that, in addition to the “default” commands mentioned above, many WordPress plugins often have their own WP-CLI commands, which you will usually discover by reading the documentation for your plugin.

Let’s presume you’re using the UpdraftPlus plugin to make backups of your website. Instead of manually making backups from your WordPress dashboard, you may use the following command to manually or automatically execute backups:

wp updraftplus backup

This is only one example; consider the plugins you use on your own pages and see if you can come up with any helpful workflows.

In conculsion

WP-CLI is a more effective and versatile way to handle WordPress pages for beginner and advanced WordPress users and developers.

How to Use WP-CLI to Manage WordPress Websites via @projects_engine. #projectsengine #wordpress #wpcli

Important links:

If you have any concerns about using the command-line interface in WordPress, p lease post your questions in the comments section.

Was this article helpful?