WP-CLI (WordPress Command Line Interface) is a robust command-line tool designed for developers and site administrators to manage WordPress sites more efficiently. Instead of navigating through the WordPress dashboard, WP-CLI enables you to perform a wide range of tasks directly from your terminal. You can install, update, and configure WordPress core, manage plugins and themes, handle user accounts, and even interact with the database—all with simple commands. This not only speeds up routine maintenance but also makes it easier to automate repetitive tasks, streamline workflows, and manage multiple sites at scale. WP-CLI is especially valuable for advanced users, agencies, and anyone looking to improve productivity or integrate WordPress management into automated deployment pipelines. Whether you’re maintaining a single blog or overseeing dozens of client sites, mastering WP-CLI can save you significant time and reduce the risk of manual errors.
This guide will walk you through the essential commands and features of WP-CLI, enabling you to supercharge your WordPress management.
Table of Contents
Open Table of Contents
Installing WP-CLI
Before you can harness the power of WP-CLI, you need to ensure it’s properly installed on your system. The installation process is straightforward and works across most UNIX-based environments. In this section, you’ll learn about the prerequisites for running WP-CLI and follow step-by-step instructions to get it up and running. Whether you’re setting up on a local machine or a remote server, these steps will help you quickly prepare your environment for efficient WordPress management.
A. System Requirements
Ensure your system meets the following requirements:
- UNIX-based OS (Linux, macOS, or Windows with WSL)
- PHP 7.4 or higher
- WordPress 5.0 or higher
- Secure Shell (SSH) access (for remote management)
B. Installation Steps
To install WP-CLI:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
Verify installation:
wp --info
Managing WordPress Core
Managing the WordPress core is a fundamental aspect of maintaining a secure and up-to-date website. With WP-CLI, you can easily check your current WordPress version, perform updates, and even install WordPress from scratch—all without leaving the command line. This section covers the essential WP-CLI commands for handling WordPress core operations, enabling you to streamline updates, automate installations, and ensure your site is always running the latest and most secure version.
A. Checking Core Version
wp core version
B. Updating WordPress Core
wp core update
C. Installing WordPress
Installing WordPress with WP-CLI is a fast and efficient process that eliminates the need for manual file uploads or web-based installers. By using a few simple commands, you can download the latest WordPress core files, configure your database connection, and complete the installation—all from your terminal. This approach is ideal for both local development and production environments, allowing you to automate deployments and maintain consistency across multiple sites. Let’s walk through the steps to install WordPress using WP-CLI.
wp core download
wp config create --dbname=wordpress --dbuser=root --dbpass=root --dbhost=localhost
wp core install --url="example.com" --title="My Site" --admin_user="admin" --admin_password="password" --admin_email="[email protected]"
Plugin Management
Managing plugins and themes is a crucial part of maintaining and customizing your WordPress site. WP-CLI makes these tasks faster and more efficient by allowing you to install, activate, update, and remove plugins and themes directly from the command line. This not only saves time but also enables bulk operations and automation, which are especially useful when managing multiple sites or staging environments. In this section, you’ll learn the essential WP-CLI commands for effective plugin and theme management.
Listing Installed Plugins
Managing plugins is essential for extending the functionality of your WordPress site. WP-CLI allows you to quickly view all installed plugins, check their status, and identify which ones are active or need updates. This command provides a clear overview, making plugin management more efficient and scalable.
wp plugin list
Installing Plugins
Installing plugins with WP-CLI is quick and efficient, allowing you to extend your site’s functionality without navigating the WordPress dashboard. With a single command, you can download and activate any plugin from the WordPress repository, making plugin management seamless and ideal for automation or bulk operations.
wp plugin install akismet --activate
Activating a Plugin
Activating plugins is a common task when managing WordPress sites, especially after installation or migration. With WP-CLI, you can activate any installed plugin instantly from the command line, making it easy to enable new features or troubleshoot issues without accessing the WordPress dashboard.
wp plugin activate akismet
Updating Plugins
Keeping your plugins up to date is vital for security and compatibility. WP-CLI allows you to update individual plugins or all plugins at once with a single command, making it easy to maintain your site and automate updates as part of your workflow.
wp plugin update --all
Deactivating and Deleting Plugins
Deactivating and deleting plugins is essential for maintaining a secure and efficient WordPress site. WP-CLI allows you to quickly disable plugins that are no longer needed and remove them entirely from your installation. This helps reduce clutter, improve performance, and minimize potential security risks.
wp plugin deactivate akismet
wp plugin delete akismet
Theme Management
Managing themes is a key aspect of customizing the appearance and functionality of your WordPress site. WP-CLI simplifies theme management by allowing you to install, activate, update, and delete themes directly from the command line. This not only speeds up the process but also enables bulk operations and automation, making it easier to maintain multiple sites or staging environments. In this section, you’ll learn the essential WP-CLI commands for effective theme management.
Listing Installed Themes
Listing installed themes is essential for keeping track of the visual options available on your WordPress site. With WP-CLI, you can quickly view all installed themes, check their status, and identify which ones are active or need updates—making theme management more transparent and efficient.
wp theme list
Installing and Activating a Theme
Installing and activating themes with WP-CLI is a fast and efficient way to customize your site’s appearance without using the WordPress dashboard. With a single command, you can download any theme from the WordPress repository and activate it immediately, making theme management ideal for automation and bulk operations.
wp theme install twentytwentytwo --activate
Updating Themes
Updating themes is crucial for maintaining site security, compatibility, and access to the latest features. WP-CLI allows you to update individual themes or all themes at once directly from the command line, streamlining the update process and making it easy to automate theme maintenance across multiple WordPress sites.
wp theme update --all
Database Management
Database management is a critical aspect of maintaining a healthy and high-performing WordPress site. WP-CLI provides powerful commands to optimize, back up, restore, and manipulate your database directly from the command line. This section covers essential database operations, enabling you to efficiently manage data and automate routine maintenance tasks.
A. Optimize Database
Optimizing your WordPress database is essential for maintaining site performance and reliability. WP-CLI makes this process simple by providing commands to clean up overhead, defragment tables, and improve query efficiency. Regular optimization helps ensure your site runs smoothly and can prevent potential database issues over time.
wp db optimize
B. Export and Import Database
Exporting and importing your WordPress database is essential for backups, migrations, and disaster recovery. WP-CLI makes these tasks straightforward, allowing you to quickly create database dumps or restore from backups directly from the command line. This section demonstrates how to efficiently export and import your WordPress database using WP-CLI.
wp db export backup.sql
wp db import backup.sql
C. Search and Replace in the Database
Performing search and replace operations in your WordPress database is often necessary during site migrations, domain changes, or bulk content updates. WP-CLI makes this process safe and efficient, allowing you to update URLs, fix typos, or modify content across your entire database with a single command—saving time and reducing manual errors.
wp search-replace 'oldsite.com' 'newsite.com'
User Management
User management is a vital part of maintaining a secure and organized WordPress site. WP-CLI allows you to efficiently list, create, update, and delete user accounts directly from the command line. This streamlines administrative tasks, supports automation, and makes it easier to manage users across multiple sites or environments.
A. Listing Users
Managing users is crucial for maintaining site security, assigning roles, and controlling access to your WordPress site. WP-CLI makes user management fast and efficient, allowing you to list all users, review their roles, and audit accounts directly from the command line—ideal for both single sites and multisite networks.
wp user list
B. Creating a New User
Creating new users is a common administrative task, especially for growing teams or client sites. WP-CLI allows you to add users quickly and assign roles directly from the command line. This streamlines onboarding, supports automation, and ensures consistent user management across single or multiple WordPress installations.
wp user create newuser [email protected] --role=editor --user_pass=securepassword
C. Changing User Password
Changing user passwords is a common administrative task, especially when onboarding new users or responding to security incidents. WP-CLI allows you to quickly and securely update user passwords directly from the command line, streamlining password resets and enhancing overall site security without needing to access the WordPress dashboard.
wp user update admin --user_pass=newpassword
Automating Tasks with WP-CLI
Automating routine tasks is one of the most powerful features of WP-CLI. By leveraging command-line scripts and scheduling tools, you can streamline maintenance, backups, updates, and more—saving time and reducing manual effort. This section explores practical ways to automate WordPress management using WP-CLI for greater efficiency and reliability.
A. Scheduling Cron Jobs
Scheduling tasks with WP-CLI allows you to automate essential maintenance and operational routines for your WordPress site. By integrating WP-CLI commands with system cron jobs, you can ensure regular execution of updates, backups, and other tasks—minimizing manual intervention and keeping your site running smoothly with minimal effort.
wp cron event run --all
B. Automating Backups
Automating regular backups is crucial for safeguarding your WordPress data and ensuring quick recovery in case of issues or data loss. With WP-CLI, you can easily schedule and execute database backups as part of your maintenance routine, integrating these commands into scripts or cron jobs for hands-free, reliable protection.
wp db export ~/backups/wp-backup-$(date +%F).sql
C. Bulk Updates
Bulk updating your WordPress installation—including the core, plugins, and themes—is essential for maintaining security and compatibility across your sites. WP-CLI enables you to perform these updates in a single command, making it easy to automate the process and ensure everything stays up to date with minimal manual intervention.
wp core update && wp plugin update --all && wp theme update --all
Best Practices for Using WP-CLI
Adopting best practices when using WP-CLI ensures safe, efficient, and reliable management of your WordPress sites. Here are some key recommendations:
-
Always Back Up First:
Before running commands that modify your site or database, create a backup. This provides a safety net in case something goes wrong. -
Test in Staging Environments:
Try new commands or scripts on a staging site before applying them to production. This helps prevent accidental data loss or downtime. -
Use Version Control:
Track changes to your codebase and configuration files with version control systems like Git. This makes it easier to roll back changes and collaborate with others. -
Limit Permissions:
Run WP-CLI commands with the least privileges necessary. Avoid using root unless required, and restrict access to sensitive environments. -
Automate with Care:
When automating tasks with scripts or cron jobs, include error handling and logging to monitor outcomes and catch issues early. -
Keep WP-CLI Updated:
Regularly update WP-CLI to benefit from the latest features, bug fixes, and security patches. -
Read the Documentation:
Refer to the official WP-CLI documentation for detailed command usage, options, and examples.
Following these best practices will help you get the most out of WP-CLI while minimizing risks and maximizing efficiency.
Frequently Asked Questions (FAQ)
-
Is WP-CLI safe to use on production sites?
Yes, WP-CLI is safe for production environments when used carefully. Always back up your site and database before running commands that make significant changes, and test new scripts in a staging environment first. -
Can I use WP-CLI with multisite WordPress installations?
Absolutely. WP-CLI fully supports WordPress multisite networks. You can manage network-wide plugins, themes, and users by specifying the--url
or--network
flags as needed. -
How do I update WP-CLI itself?
To update WP-CLI, simply run the following command:wp cli update
WP-CLI is an indispensable tool for WordPress developers and administrators. It streamlines site management, automates repetitive tasks, and enhances efficiency. Mastering WP-CLI will significantly improve your workflow and productivity.
Are you ready to supercharge your WordPress management with WP-CLI? 🚀