Installing and Working With WordPress CLI

Posted By : Harsh Soni | 28-Feb-2018

In this tutorial, we are going to work with Wordpress command line interface (WP-CLI). It is specifically developed to manage WordPress websites using CLI. As it makes the WordPress work easier, it also allows working faster with WordPress. We can manage WordPress and its setting without navigating and clicking on several pages.

 

Using WordPress CLI  we can complete the administrative tasks like updating themes, plugins installations, publishing post and many more. Before installing WP-CLI, You should make sure your hosting account has SSH access to you.

 

Basic Requirements

 

  • PHP(5.3.2 or later)
  • WordPress (3.4 or later)
  • UNIX like environment like Ubuntu, Linux.

 

Installing WP-CLI

 

Open the terminal and paste the below code

 

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

 

It will download the WP-CLI files to your root directory. Now, we will make it executable by using this command.

 

chmod +x wp-cli.phar

 

type this to check if it works

 

php wp-cli.phar --info

 

to use "wp" at command start instead of "php wp-cli.phar" move the wp-cli.phar file to a wp directory

 

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

 

Now we can execute WP-CLI commands by using 'wp'. You can also try "wp --info" command.

 

Installing WordPress setup on the server using WP-CLI.

 

We can install the WordPress using a single command "wp core install". Only we have to pass few parameters such as site name, admin name, URL etc.

 

wp core install --url="DomainURL"  --title="Website Title" --admin_user="adminUsername" --admin_password="adminPassword" --admin_email="adminEmail"

 

Installing themes and plugins using WP-CLI

 

If you have spent lots of time clicking and installing plugins and themes from the dashboard, this feature will amaze you. It is much quicker than doing it manually.

 

wp theme install twentyeighteen

 

the above command will install the twewentyeighteen theme, to activate the theme you can use

 

wp theme activate twentyeighteen

 

Similarly, you can install and activate plugins using these commands

 

wp plugin install woocommerce
     wp plugin activate woocommerce

 

Updating plugins and Themes using WP-CLI

 

You can save our time to update the core and plugins by using this single line commands.

 

To update the core to the latest release, you can use this command.

 

wp core update

 

you can also install the specific version of WordPress

 

wp core update --version=4.7

 

you can also revert back to the previous version forcefully by amending this command at the end of above command

 

wp core update --version=4.4 --force

 

TO update the themes and plugins individually you can use this command

 

wp theme update twentyseventeen
wp plugin update woocommerce

 

to update all you can use the below command

 

wp theme update --all
wp plugin update --all

 

You can read about the WP-CLI commands. There are lots of commands to update post, comments, options, take DB backup etc. You can control the WordPress structure using the CLI and can save lots of time to implement on other projects.

Resources: WordPress CLI

About Author

Author Image
Harsh Soni

Harsh is an experienced software developer with a specialization in the MEAN stack. He is skilled in a wide range of web technologies, including Angular, Node.js, PHP, AWS, and Docker.Throughout his career, Harsh has demonstrated a strong commitment to delivering high-quality software solutions that meet the unique needs of his clients and organizations. His proficiency in Angular and Node.js has allowed him to build dynamic and interactive user interfaces, leveraging the power of modern front-end frameworks. Harsh's expertise also extends to cloud computing and infrastructure management using AWS, enabling him to design and deploy scalable applications with ease. Additionally, his knowledge of Docker has enabled him to streamline the development and deployment process, enhancing efficiency and reducing time-to-market. He excels at analyzing complex technical challenges and devising efficient strategies to overcome them, ensuring the successful completion of projects within deadlines.

Request for Proposal

Name is required

Comment is required

Sending message..