How to Use the WP-CLI to Manage Your WordPress Site
With the different commands available on WP-CLI, there is nothing that cannot be done via the command line. Find below a list of some actions that can be performed using commands.
1. Install and Update WordPress
Downloading and installing WordPress on your site is the most fundamental task you can accomplish with WP-CLI
To download WordPress use this command:
wp core download
To refine the download further to the version you want use this command:
wp core download --locale=en-US
This command will download the English version of WordPress
Proceed to install WordPress using the install command:
wp core install --url=testing.com --title=Example --admin_user=supervisor --admin_password=strongpassword [email protected]
Note: Replace the default values with your credentials.
Test the installation to confirm WordPress has been successfully installed using this command:
wp core version
Update to the latest version using this command:
wp core update
2 . Manage Themes and Plugins
There are different ways to manage themes and plugins using WP-CLI, let’s take a look at some of the basic options
Managing Themes via WP-CLI
To list installed themes use this command:
wp theme list
To list all inactive themes as a CSV list, use this command:
wp theme list --status=inactive --format=csv
To change an active theme to twenty-twenty, use this command:
wp theme activate twenty twenty
To search for themes with Bootstrap support:
wp theme search bootstrap
Using this command, proceed to install and activate:
wp theme install the-bootstrap-blog --activate
To enable a theme using Twenty twenty theme, use this command:
wp theme enable twenty twenty
To update themes use this command:
wp theme update --all
To list all currently installed plugins, use this command:
Managing Plugins via WP-CLI
To install and activate a plugin use this command:
wp plugin install litespeed-cache --activate
Run this command to update plugins:
wp plugin update --all
Note that the –all parameter is used to update all installed plugins.
This can be changed to a specific plugin by replacing –all with the plugin name.
Using the litespeed-cache plugin, disable and uninstall a plugin:
wp plugin deactivate litespeed-cache –uninstall
To activate any inactive plugin, use this command:
wp plugin activate litespeed-cache
To find WordPress cache plugins use the following command:
wp plugin search cache
To delete plugins use the wp plugin delete command:
wp plugin delete litespeed-cache
3. Create a Child Theme
By using the scaffold command, you can generate a child theme that includes the functions.php and style.css files. We recommend that you do this if you want to make changes to an existing theme. When you use a child theme, any customization won’t be lost after new software updates.
To do this, you’ll simply need to specify the slug for the new child theme, and for the theme, you’re using as the ‘parent.’ In this example, we are creating a child based on the Twenty Twenty theme, and we’re giving it the slug twenty-twenty-child:
wp scaffold child-theme twenty-twenty-child --parent_theme=twentytwenty
You will get a successful message that the child theme has been created.
and find the child theme in the specified template.
4. Moderate Comments
With WP-CLI, you can quickly create, edit and delete comments making managing comments much easier. There are many comment subcommands you can use, but let’s look at some of the most basic options.
To add a new comment, use this command. This command will add a comment to a post with the post ID of 10, and state the author and contents:
wp comment create --comment_post_ID=10 --comment_content="This is my comment" --comment_author="author-name"
This command will return a table containing the comment ID and author name for all approved comments on the post with an ID of 5:
wp comment list --number=5 --status=approve --fields=ID,comment_author
To delete comments, specify the comment IDs individually, like this:
wp comment delete 46
To delete multiple comments using the force parameter, which permanently deletes comments instead of adding them to the trash bin:
wp comment delete 3 25 46 54 --force
Using WP-CLI commands you can work through your site’s comments
5. Update the WP-CLI
You should always make sure that WP-CLI is updated at all times.
To update WP-CLI run the following command:
wp cli update
If your version is updated, you will get a successful message confirming this, however, if you are running a version that is not updated, you will be prompted to accept the installation, selecting yes will get WP-CLI updated
With a simple interface like WP-CLI you can perform functions unavailable in WordPress, complete multiple tasks using a single command and improve productivity,
Updated 5 months ago