Mastering WordPress Administration: Top 10 WP-CLI Commands You Need to Know

As a WordPress administrator, efficiency and automation are key to managing your website effectively.

WP-CLI (WordPress Command-Line Interface) is a powerful tool that allows you to interact with your WordPress site through the command line, providing a faster and more efficient way to perform administrative tasks.

In this article, we’ll explore the top 10 WP-CLI commands that will streamline your WordPress management workflow. We’ll also provide examples to demonstrate how to use these commands effectively.

Installing and Updating WordPress Core

WP-CLI simplifies the process of installing and updating WordPress. Use the following commands to get started:

# Download and install the latest version of WordPress
wp core download

# Update WordPress to the latest version
wp core update

Managing Plugins

WP-CLI enables you to manage plugins without accessing the WordPress dashboard. Here are some useful commands:

# Install a plugin from the WordPress.org Plugin Repository
wp plugin install <plugin-slug>

# Activate a plugin
wp plugin activate <plugin-slug>

# Deactivate a plugin
wp plugin deactivate <plugin-slug>

# Update all installed plugins
wp plugin update --all

Managing Themes

Effortlessly control your WordPress themes with WP-CLI. Execute these commands to handle theme-related tasks:

# Install a theme from the WordPress.org Theme Repository
wp theme install <theme-slug>

# Activate a theme
wp theme activate <theme-slug>

# Update all installed themes
wp theme update --all

# List installed themes
wp theme list

Managing Users

With WP-CLI, user management becomes a breeze. Use the following commands to create, modify, or delete users:

# Create a new user
wp user create <username> <email> --role=<role>

# Update a user's password
wp user update <user-id> --user_pass=<password>

# Delete a user
wp user delete <user-id> --reassign=<new-user-id>

Database Management

WP-CLI simplifies database-related tasks, allowing you to optimize, repair, and manage your WordPress database with ease:

# Optimize the database
wp db optimize

# Repair the database
wp db repair

# Execute a SQL query
wp db query "SELECT * FROM wp_posts"

Managing Posts and Pages

Save time and effort by using WP-CLI commands to create, update, and delete posts and pages:

# Create a new post
wp post create --post_type=<post-type> --post_title=<title> --post_status=<status>

# Update a post
wp post update <post-id> --post_title=<new-title>

# Delete a post
wp post delete <post-id> --force

Importing and Exporting Data

WP-CLI allows you to import and export content effortlessly. Here’s how:

# Import content from an XML file
wp import <file.xml> --authors=create

# Export content to an XML file
wp export --dir=<export-directory>

Managing Widgets

Manage your website’s widgets efficiently using WP-CLI:

# List available widgets
wp widget list

# Add a widget to a specific sidebar
wp widget add <widget-id> <sidebar-id> --position=<position>

# Remove a widget from a sidebar
wp widget remove <widget-id> <sidebar-id>

Debugging and Logging

WP-CLI provides valuable debugging and logging options to help troubleshoot issues:

# Enable WordPress debugging
wp config set WP_DEBUG true

# Display WordPress debugging information
wp debug

# Clear the debug log
wp debug log --clear

Multisite Management

For WordPress multisite administrators, WP-CLI offers commands to manage multiple sites from a single interface:

# Create a new site
wp site create --slug=<slug> --title=<title> --email=<email>

# List all sites in the network
wp site list

# Switch to a specific site
wp site switch <site-id>

Conclusion

WP-CLI is an indispensable tool for WordPress administrators, empowering them to perform a wide range of tasks efficiently from the command line. By familiarizing yourself with these top 10 WP-CLI commands and their usage, you can save time and simplify your WordPress management workflow. Embrace the power of WP-CLI and take control of your WordPress site like a pro.

Jan Horecny

Jan Horecny

Jan Horecny is a highly skilled Lead Senior Developer at GALTON Brands, specializing in WordPress development, PHP, and databases. With a keen eye for detail and a passion for creating exceptional online experiences, Jan consistently delivers top-notch solutions that drive results. His extensive expertise in WordPress, coupled with his deep understanding of PHP and database management, enables him to design and develop robust, scalable, and user-friendly websites.