What is WP-CLI? Important Command for WordPress

siddhant sugan dodrai
By -

As you become more proficient in developing WordPress, you will need some tools that will enable you to complete your tasks faster and more efficiently. What is WP-CLI? Important Command for WordPress .

What is WP-CLI? Important Command for WordPress

The WordPress admin dashboard is very user-friendly and well-structured, but it can be time-consuming.

But what if you want to be able to directly manage your site with just a few simple commands? That’s where the WordPress command line interface comes into play.

WP-CLI stands for “WordPress Command Language Interface.” It’s a command-based interface that allows you to interact directly with your WordPress site. The interface is text-based and has a large number of possible commands. Almost anything that can be done on the backend of your site can be done in a fraction of the time using a WP-CLI.

What is WP-CLI?

Like most of us, you’ve probably heard a lot about the WordPress admin section. It’s functional, sure, but it isn’t the only way to manage your site. And it’s certainly not the most straightforward or efficient way.

Yes, having a graphical interface is definitely better for some users. But it also means you’ll be spending a lot of time scrolling through menus and waiting for pages to show up.
WP-CLI stands for “WordPress Command Line Interface”. This is a tool that allows you to execute commands on your WordPress site directly from the command line. In other words, you can just type a line of code into the command line and hit Enter to complete the task.

WP-CLI is a great tool because it allows you to directly control your site. You can do anything you can do in your WordPress admin dashboard. It is not as complicated as you might think. There are plenty of resources to help you learn more about this tool.

In order to use WP-CLI on your WordPress site, you will need to install it. Let's take a closer look at the process.

How to install WordPress CLI?

If you’re hosting your site on VPS, you’ll have to install it during our tutorial. But if you’re not, you can manually install this tool.

First, you need to ensure that your environment meets the following requirements:

🔹OS X (OS X-based)
🔹Linux (FreeBSD-based)
🔹PHP (PHP-5.6 or higher)
🔹WordPress (3.7 or higher)

The first requirement might come as a surprise to some users. This tool is specifically designed for UNIX-based environments and has limited Windows support. You can still install it, but you’ll need to do some extra work.
Some users might be surprised by the first point. The WP-CLI is built for UNIX environments and has limited support for Windows. You can install it on Windows, but be aware that it might take some time to get it working.

To install WP-CLI on any of the above environments, you’ll need to download and configure the necessary files using the Secure Shell utility.

To get started, download the necessary files:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Next, run the following command to verify if the file works:

php wp-cli.phar --info
Next, you will need to execute the file, which will allow you to execute the wp file. You will also need to move the file to a different directory. This last command will do both.
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
With that, you should be good to go. You can check if everything is working by running the following command: wp -info.

If everything works as expected, you should be able to see information about the version of the Wp-CLI that you have installed.

And that’s all there is to it! Now you can start using this tool to run your site more effectively.

Let’s take a look at some of the alternative ways to install the wp-cli.

Other Alternate Way to install Wp-CLI

As mentioned above, there are actually a few different ways to install the Wp-CLI. In this article, we will not cover all of them. However, we will briefly list them below and provide links to more information about each method, so that you can choose the one that works best for you.

The following tools can be used to install the wp-cli on your website:

✔️wp-cli.deb package
✔️a custom PHP binary

Last but not least, you may also want to contribute to the development of theWP-CLI. You can do this by following the Git installation guide.

How to Use Wp-CLI and Important Command for WordPress

WP-CLI gives you complete control over your site — at your fingertips. You can use dozens of commands to manage almost everything on your site, from commenting to core updates. Custom commands are also available.

Let’s take a quick look at some of the standard commands you can use with WP-CLI, before we dive deeper into all the options.

1. Install and Update WordPress

The most important thing you can do with WP-CLI, is to download and set up WordPress on your website. The command to download WordPress is as follows:
wp core download
This command downloads and extracts WordPress from the directory you are in. If you want to make the download even better, you can add more parameters. For instance, if you specify the locale parameter, this command will download WordPress in the Brazilian Portuguese language.
wp core download --locale=pt_BR
Once you have downloaded WordPress, you can use the install command to install it. This command has several parameters that set up the installation. Let's see an example:
wp core install --url=example.com
It's all pretty straightforward. All you have to do is substitute your own values for the example values in each parameter. You can test the installation by running the following command:
wp core version 
This will return your installation version number, meaning you have successfully installed WordPress. Now, you can check if it is up to date with the following command:
wp core update 
If you have an older version of WordPress, it will automatically download and install it after you execute this command.

2. Manage your WordPress Theme and Plugin

WP-CLI themes and plugins can be managed in a variety of ways. Let’s start with some of the basics.

The list command can be used to display a list of the themes or plugins you have. You can use parameters to filter the list by items that have a certain status (e.g. inactive) or output format. For example, you can list all the inactive themes in a CSV list using the following command:
wp theme list --status=inactive -- 
You can also add a plugin by adding its slug to the plugin directory. You can also add a local file's path or enter the URL of an external file to install the plugin. In this case, we will also activate the plugin simultaneously.
wp plugin install ../my-plugin.zip
You can also modify the status of the plugin or theme. For example, you can use the following command to enable a theme:
wp theme enable twentytwenty
You can also use the deactivate plugin command. For example, we will use this command to deactivate the hello doll plugin. We will also uninstall the plugin simultaneously.

You can also search the directories for a particular plugin or theme.

For example, let's search for a theme that contains the string "photo". We are also going to set it to return 3 results instead of 10.
wp theme search photo --per-page=3 
Wp-cli output

As we said, this is just a taste of what you can do with WP-CLI themes and plugins. I hope you’re starting to understand how powerful this tool can be.

3. Create a child theme using WP-CLI

You can use the scaffold command to create a child theme that contains the functions.php file and style.css file. It is recommended to use a child theme if you want to modify an existing theme. Using a child theme means that any customizations will not be lost after a software update.

To create a child theme, you must specify the slug for your new child theme and the theme you are using as ‘parent’. For example, in this example, we are making a child based on our Twenty Twenty theme and we are giving it the slug 20-child.
wp scaffold child-theme twentytwenty-child --parent_theme=twentytwenty
If the process is completed successfully, you will receive a notification that the child theme is created. The message will also contain the directory of the child theme.
Success: Created '/var/www/example.com/public_html/wp-content/themes/twentytwenty-theme'
You will now see the child theme in your template, ready for editing!

4. Moderate Your WordPress Comments

WordPress Language (WP-CLI) allows you to create, remove, and edit comments in a few simple steps. There are a lot of subcommands that you can use to manage comments, but here are some of the basics.

The first step is to add a comment. This command adds a new comment to your post with post ID 20. You can specify the content and author of the comment.

wp comment create --comment_post_ID=20 --comment_content="This is my comment" --comment_author="author-name"
Before you manage the current comments, you can get a list of them. You can use the list command to get a list, and you can filter the results in many different ways.

For example, the list command returns a table with the comment ID, and the author name of all the approved comments in the post with ID 3.
wp comment list --number=3 --status=approve --fields=ID,comment_author
Output CLI table

To remove comments, you can specify the comment IDs one at a time, such as:

wp comment delete 64
You can also remove multiple comments by indenting each comment ID. In this case, we also use the force parameter that permanently removes comments instead of putting them in the trash.
wp comment delete 5 22 64 64 --force
With a bit of practice, you can quickly and easily navigate through your website’s comments with the help of WP-CLI statements.

5. Update Your WP-CLI

WP-CLI is one of the most important components of WordPress. As with any other part of your site, you should always keep it up to date. The good news is that it’s very easy. All you have to do is execute the following command:

wp cli update
If you are using the latest version, you will receive a confirmation message. However, if you can download a new version, you will be asked to accept installation. If you choose to accept installation, you will see a confirmation message that your WP-CLI is updated.
Success: Updated WP-CLI to 0.23.1
With this update, you have upgraded your installation to the latest version of the WpCLI. You are now starting to understand what you can achieve with this easy-to-use interface. You still have a lot of learning to do, but you have come a long way!

Wp-cli Important Command List

wp helpDetails about command and options
wp cli versionTo check the WP CLI version
php wp-cli.phar –infoMaking file executable
wp core downloadDownload the latest version of the WordPress core files
wp config createCreate config file
wp db createCreate a new DB
wp theme installInstall theme
wp theme activateActivate theme
wp theme deactivateDeactivate theme
wp plugin installInstall plugin
wp plugin activateActivate plugin
wp search-replaceSearches/replaces strings in DB
wp help pluginDetails about the Plugin command

Depending on what you are trying to achieve on your WordPress site, there are many more of these commands available. Check out the official documentation for a complete list and instructions on how to use these commands.


Speed, scalability, and ease of use are just a few of the features that every smart developer wants in their toolbox. The WordPress-CLI provides all these features and more while allowing you to run your WordPress site from anywhere in the world. With the help of the WordPress-CLI you can do everything that is possible in your WordPress admin — only much faster (after you get a little practice).

WP-CLI comes with a variety of commands that make it simple to install, enable, disable, update and control WordPress plugins and themes, as well as core files. You can also control posts, users and even the WordPress database.

WP-CLI is one of the most powerful tools for managing WordPress sites. It can help you manage a single site as well as multiple sites at the same time. By mastering the various commands, you can make your workflow more efficient and save you a lot of time.

Become an Effective WordPress Site Manager and Developer.

Post a Comment


Post a Comment (0)

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn more
Ok, Go it!