If you’re managing a WordPress website, you know that there are a lot of tasks that need to be performed regularly to keep your site up and running smoothly. While there are many ways to accomplish these tasks, one tool that can make your life easier is WP-CLI.
WP-CLI is a command-line interface for WordPress that allows you to manage your website from the terminal. In this post, we’ll look at some of the cool things you can do with WP-CLI to manage your WordPress website.
1. Installing and Updating Plugins and Themes
One of the most common tasks that you need to perform when managing a WordPress website is installing and updating plugins and themes. With WP-CLI, you can easily do this from the terminal. To install a plugin or theme, you simply need to use the
wp plugin install or
wp theme install command.
For example, to install the popular Yoast SEO plugin, you would use the following command:
wp plugin install wordpress-seo
To update a plugin or theme, you can use the
wp plugin update or
wp theme update command. For example, to update the Yoast SEO plugin, you would use the following command:
wp plugin update wordpress-seo
If you want to update all plugins and themes you would run the following command:
wp plugin update --all && wp theme update --all
Now if you want to get a quick summary of pending updates on both plugins and themes, you can run this:
wp plugin list --update=available && wp theme list --update=available
A common mistake on WordPress website is to have a lot of inactive plugins, this a security risk and it just a waste of space on your disk, to get rid of all those plugins try this:
wp plugin delete $(wp plugin list --status=inactive --field=name)
2. Managing Users
Another important task that you need to perform when managing a WordPress website is managing users. With WP-CLI, you can easily add, delete, and modify users from the terminal. To add a user, you can use the
wp user create command.
For example, to add a user with the username “john” and the email “[email protected]“, you would use the following command:
wp user create john [email protected] --role=editor --user_pass=strongpassword
To delete a user, you can use the
wp user delete command. For example, to delete the user with the ID 5, you would use the following command:
wp user delete 5
To modify a user, you can use the
wp user update command. For example, to change the email address of the user with the ID 5 to “[email protected]“, you would use the following command:
wp user update 5 [email protected]
Now, let’s talk about doing bulk actions to users. If you want to force a password reset on all administrators, you can do it like this:
wp user reset-password $(wp user list --role=administrator --field=user_login)
Pretty cool isn’t? Drop a comment below if you want more examples!
3. Managing Posts and Pages
WP-CLI also allows you to manage your WordPress posts and pages from the terminal. You can create, edit, and delete posts and pages using the
wp post create,
wp post update,
wp post delete,
wp page create,
wp page update, and
wp page delete commands.
For example, to create a new post with the title “My New Post” and the content “This is my new post.”, you would use the following command:
wp post create --post_title='My New Post' --post_content='This is my new post.'
To update a post with the ID 5 and change the title to “My Updated Post”, you would use the following command:
wp post delete 5
The following command is useful when you are developing a site and you need some dummy posts just to see of the blog archive and blog post pages look like, you can generate 100 differents posts with this:
wp post generate --count=100 --post_type=post
4. Managing WordPress Core
Finally, WP-CLI also allows you to manage your WordPress core installation from the terminal. You can update your WordPress installation using the
wp core update command, and you can also install and uninstall WordPress using the
wp core download and
wp core delete commands.
For example, to update your WordPress installation, you would use the following command:
wp core update
To install a new WordPress installation, you would use the following command:
wp core download --locale=en_US
To delete your WordPress installation, you use the next command:
wp core delete
In conclusion, WP-CLI is a powerful tool that can make managing your WordPress website from the terminal a breeze. With WP-CLI, you can install and update plugins and themes, manage users, create and edit posts and pages, and manage your WordPress core installation. This can save you time and make your workflow more efficient.
So, if you’re not already using WP-CLI to manage your WordPress website, give it a try and see how it can help you streamline your website management tasks. Be sure to read their handbook for all commands and more useful examples.
Most shared hosting companies such as SiteGround and BlueHost offer WP-CLI on their plans that come with SSH access. But if you need a more stable hosting with WP-CLI, SSH, Git and other tools, be sure to check Kinsta. They are on Google Cloud and offer scalable services.