WordPress features an intuitive Graphical User Interface (GUI) that enables users to develop their sites with ease. However, putting ease of use first sometimes results in less than ideal efficiency, and WordPress falls into that trap in some aspects.
Working with the WordPress Command Line Interface (WP-CLI) tool will enable you to tackle administrative tasks more efficiently. For instance, if you wanted to create a child theme manually, you’d need to go through several steps. Using WP-CLI, you can get it done with a single command.
In this post, we’ll discuss some of the different ways you can use WP-CLI to speed up WordPress development, including site setup, maintenance, and plugin management. However, before we get to that, let’s take a closer look at the tool and the features it offers.
A Brief Overview of WP-CLI
If you have a background in web development, you probably already know what a command line interface is, and you’ll feel right at home using WP-CLI. This straightforward tool makes it easy for WordPress users to interact with the platform. Furthermore, it enables developers to speed up day-to-day tasks by using simple commands instead of shuffling from one tab to another using the platform’s dashboard.
To that end, the tool supports nearly every action you need to manage a WordPress site, including:
- Installing the platform
- Executing WordPress core updates
- Managing WordPress themes and plugins
- Creating child themes
- Importing media files in bulk
Regardless of whether you’re working on a test site, a live installation, or a multi-site network, WP-CLI can help make your life easier. To get started, all you have to do is set it up and learn how to use its built-in commands. Let’s start with the former.
Setting Up WP-CLI
Before you can start having fun with WP-CLI, you need to make sure your hosting environment meets its basic setup requirements. Here’s the criteria you need to keep in mind:
- A UNIX-like environment.
- PHP 5.3.29 (or later).
- WordPress 3.7 (or later).
- Secure Shell (SSH) access to your hosting environment.
If your provider meets those requirements, then you’re good to go. The best way to install the tool is by downloading its .phar file using the curl command, as seen below:
$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Once that’s done, run the following command to make sure the tool is set up properly:
$ php wp-cli.phar –info
If the installation went off without a hitch, you should see a message similar to this one, indicating which version of WP-CLI you’re running:
PHP binary: /usr/bin/php5 PHP version: 5.5.9-1ubuntu4.14 php.ini used: /etc/php5/cli/php.ini WP-CLI root dir: /home/wp-cli/.wp-cli WP-CLI packages dir: /home/wp-cli/.wp-cli/packages/ WP-CLI global config: /home/wp-cli/.wp-cli/config.yml WP-CLI project config: WP-CLI version: 0.23.0
At this stage, we recommend that you create an executable file for WP-CLI and move the tool to its own folder (preferably called wp). Here’s the code you’ll need to run to pull it off:
$ chmod +x wp-cli.phar $ sudo mv wp-cli.phar /usr/local/bin/wp
Doing this will let you use WP-CLI from your own command line with the wp command. If you run into any issues during the installation process (which you probably won’t), you might want to check out this handbook on alternative setup methods for WP-CLI.
3 Ways to Speed Up WordPress Development Using WP-CLI
In this section, we’ll go over some of the most common scenarios where using WP-CLI makes more sense than WordPress’ GUI from an efficiency standpoint. Please note that we’ll be using placeholders throughout the code in this section – don’t forget to replace them with your own information if you copy these snippets!
1. Install and Update WordPress
To install WordPress using WP-CLI, all you have to do is locate the directory where you want to set it up and run the following command:
wp core download
Next, create a wp-config.php file in the same directory using this line of code:
wp core config --dbname=databasename --dbuser=databaseuser --dbpass=databasepassword --dbhost=localhost --dbprefix=prfx_
Finally, you’ll need to execute the core install command to kick off the process. Please note we’ve added a few additional parameters to this command, specifying our admin username, password, and email. Replace those with your own before running it.
wp core install –url=example.com –title=”Your WordPress Site's Title” –admin_user=admin_user –admin_password=admin_password –[email protected]
That command will install the latest version of WordPress, but at some point, you’re going to need to update the platform. When that happens, you’ll need to use this command:
wp core update
Once the platform is fully updated, you’ll want to do the same for your database:
wp core update -db
As you can see, all it takes are a few lines of code to execute complex processes using WP-CLI. With some practice, you’ll come to know them by heart, rendering the entire process that much more efficient.
2. Manage Your WordPress Themes and Plugins
Managing WordPress themes and plugins using WP-CLI is a breeze. Each task can be executed with a single line of code, which is potentially far more efficient than having to go to your WordPress dashboard each time you need to make a change.
Best of all, WP-CLI automatically connects to the official WordPress theme and plugin directories, which means you can install both types of add-ons without having to download any files by hand. Here’s the list of the most common commands you’ll need to know to interact with themes and plugins:
Managing Themes
- Install: wp theme install theme’s_name
- Activate: wp theme activate theme’s_name
- Update: wp theme update theme’s_name
- Update all themes: wp theme update -all
Managing Plugins
- Install: wp plugin install plugin’s_name
- Activate: wp plugin activate plugin’s_name
- Update: wp plugin update plugin’s_name
- Update all plugins: wp plugin update -all
There are a few other commands you can use for both themes and plugins, but they’re far less likely to come up during regular WordPress maintenance. If you want to find out more about them, check out WP-CLI’s official documentation on the subject.
3. Create Child Themes
Creating a child theme manually is a lengthy process. However, WP-CLI makes it much simpler by enabling you to do it using a single command, as we mentioned at the beginning of this article. Here’s how:
wp scaffold child-theme name-of-child-theme --parent_theme=name_of_parent_theme --theme_name='My Child Theme' --activate
All you need to do is configure the parameters to your specifications and your new child theme will be up and running in a matter of seconds. That means selecting a parent theme and a name for its child. Those two aren’t the only parameters available, but they’re all you need to know to get started.
Conclusion
WP-CLI is a powerful tool that enables you to dramatically speed up your WordPress development workflow. It might take you a while to memorize its commands, but you can always refer back to this guide until you learn them by heart.
Let’s quickly recap how WP-CLI can help you speed up development in WordPress:
- Installing and updating WordPress: It enables you to skip the 5-minute WordPress installation process by using a few simple commands.
- Managing WordPress themes and plugins: WP-CLI makes installing, updating, and activating WordPress themes and plugins dead simple.
- Creating child themes: You can simplify the process of creating a child theme into a single line of code.
Do you have any questions about using WP-CLI? Let us know in the comments section below!
Image credit: Pixabay.
No Comments