How To Use WordPress CLI

0
67

What Is WP-CLI?.

WP-CLI is the command-line interface for WordPress which you can use to manage your WordPress website.

With simple command lines, you can manage your WordPress while being offline i.e. without any need of login to your WordPress admin page.

In this section, you’re going to learn about how to install WP-CLI and its uses.

Note:- WP-CLI will be particularly useful if you are a WordPress developer, System Administrator or run a business built around WordPress. It will greatly help you do more in less time. For instance, taking backups, updating WordPress and plugins, publishing content and querying databases can be accomplished relatively quickly.

Requirements of WP-CLI.

To install WP-CLI, be sure that you have a hosting account with SSH access. Most shared hosting providers do not give you access to SSH. Providers like DigitalOcean, Linode and AWS are ideal for this if you love to spin up your own servers.

Other requirements are basic:

  1. WordPress 3.7 or later
  2. UNIX like environment like (OS X, Linux, FreeBSD, Cygwin); Limited support in windows environment
  3. PHP 5.4 or later

How to Install WP-CLI

Step 1

Download the WP-CLI file “wp-cli.phar” at https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar using the “wget or curl” command.

Using the curl command, type the below command line into your command prompt:

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

This will download and extract the WP-CLI files to your root user directory.

Step 2

Now, set the permissions to make it executable. Enter the following command into your command prompt:

chmod +x wp-cli.phar

Step 3

You can move “wp-cli.phar” to a folder and rename it as wp. This will help us use the WP-CLI commands by just typing ‘wp’ at the start of the commands.

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

Now, to verify if it’s working, type php wp-cli.phar –info into your command prompt. It will show you something like this if it is working

wp-cli.org

Now we can jump in to use many of the WP-CLI commands.

WP-CLI Commands

Click here to see more.

Using the WP-CLI Help System

WP-CLI comes with a full help system that you can access by typing “wp help”, for example:

wp help cache

Will display information as:

NAME

wp cache                                                                                                                                  

DESCRIPTION

Manage the object cache.                                                                                                                   

SYNOPSIS

wp cache <command>                                                                                     etc.                                    

Examples

USES OF WP-CLI

1. Installing WordPress using WP-CLI

If you haven’t installed WordPress, then you can use WP-CLI command to install your WordPress

Type this command  wp core install along with that command you will need to attach parameters like URL, Title, Admin Username, Password and Admin Email into your command prompt.

wp core install –url=”your_domain”  –title=”Blog Title” –admin_user=”admin username” –admin_password=”enter_your_password” –admin_email=”enter_your_email”

2.Installing WordPress Theme USING WP-CLI

You can import and install WordPress themes quicker using WP-CLI than going into WordPress admin, searching and then activating it.

It connects your server directly to the WordPress theme repository and imports the theme in a matter of a few seconds. For example, to install a theme like Twenty Nineteen, we will use the following command:

wp theme install twentyninetten

Similarly, to install Buildo theme, your command will become:

wp theme install buildo

To activate the themes on your WordPress website, type the following command line:

wp theme activate twentynineteen

wp theme activate buildo

respectively.

3. Installing Plugins using WP-CLI

Like you installed your WordPress themes, you can also install your WordPress plugins using wp-cli right from the official repository. Installation is easy and saves times.

For example to install a WooCommerce plugin, just type   : wp plugin install woocommerce

Into your command prompt.

To activate it, you will use the command:

wp plugin activate woocommerce

Similarly, to deactivate any plugin, the command becomes:

wp plugin deactivate woocommerce

4. Updating WordPress Core, Themes and Plugins with WP-CLI

Updating the WordPress core, themes and plugins can also be easily carried out using WP_CLI

To update your WordPress core to the latest stable release of WordPress, the command is:

wp core update

If you want to update to a specific version, for example you have WordPress 4.0 and want to upgrade it to WordPress 5.0 instead of WordPress 4.3, use the command:

wp core update –version=5.0

Or, if for any reason you want to revert back your WordPress site to the previous version, the command is:

wp core update –version=4.0 –force

To update plugins, you can either define one plugin to update or better still, update all the plugins in one go.

TO update a plugin, for example WooCommerce

wp plugin update woocommerce.

To update all your plugins

wp plugin update –all

This method also applies to themes update. You can update WordPress themes through WP-CLI with following command

To update a theme

wp theme update twentynineteen

To update all themes

wp theme update –all.

Create A Post

 To create a post, use the following command:

To Delete a Post

If you do not need a certain post you can easily delete it:

In conclusion, WP-CLI is a great tool that can be used to manage your WordPress sites through the command line. There are also many more commands to manage your database, take backups, manage posts, comments and WordPress multisite. It speeds up your tasks, save times and makes it really easy to manage the sites.

You can also check;

5 Best Backup Plugins for WordPress
HOW TO SETUP AN ECOMMERCE STORE ON WORDPRESS WITH WOOCOMMERCE.
How To Turn Your WordPress Site Into An Android/iOS App.


LEAVE A REPLY

Please enter your comment!
Please enter your name here