WP-CLI is a command-line tool used to manage your WordPress website without needing to log in to the dashboard and navigate through the pages. In this tutorial, we’re going to go over how to manage your WordPress installation via the WP-CLI tool.
Install wp-cli via curl as shown below.
#curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
To verify it’s working use:
#php wp-cli.phar –info
you need to make it executable via:
#chmod +x wp-cli.phar
To make the tool available server-wide, move it to /usr/local/bin/ as rename it as wp.
# mv wp-cli.phar /usr/local/bin/wp
To check the version installed:
# wp cli version
Some of the useful commands are provided below:
1) To list the plugins under a wordpress domain.
You need to navigate to the document root of the domain and execute the command below:
#wp plugin list
It shows which all are are active, inactive and if updates are available.
2) If you want to install plugins.
#wp plugin install gutenberg two-factor jetpack
In the above example, the plugins which going to be installed are: gutenberg, two-factor and jetpack.
3) If you want to install a specific version of the plugin.
#wp plugin install two-factor –version=0.7.1
4) To activate/deactivate a plugin
#wp plugin activate plugin-name
and to deactivate
#wp plugin deactivate plugin-name
To activate/deactivate all plugins:
#wp plugin activate –all
#wp plugin deactivate –all
5) To update a plugin
#wp plugin update two-factor
6) To install a theme
#wp theme install smart-mag –activate
7) To list all the themes inside themes folder
#wp theme list
8) To list the posts
#wp post list
and we can remove the post vis using its ID:
#wp post delete 1
1 is the ID of the post, and here, we are deleting the post with post_title “Hello world!”.
9) To update wordpress core files.
This is a crucial update process, so test plugins and themes before upgrading wordpress, and keep a backup before updating.
To check the core version:
#wp core version
The output is:
To update the version use:
#wp core update