Essential WPCli Commands

WP-CLI (WordPress Command Line Interface) is a powerful command-line tool that allows you to manage various aspects of a WordPress site directly from the command line. It provides a set of commands that can be used to perform tasks such as installing, updating, and managing WordPress installations, themes, plugins, users, and more, without the need to use a web browser.

Here are some common tasks you can accomplish using WP-CLI:

  1. Installing WordPress: You can create a new WordPress installation with just a few commands.
  2. Managing Plugins and Themes: WP-CLI allows you to install, activate, deactivate, and delete plugins and themes from the command line.
  3. Updating WordPress Core, Plugins, and Themes: You can update WordPress core, plugins, and themes with a single command.
  4. Managing Users: You can create, delete, and modify user accounts directly from the command line.
  5. Importing and Exporting Content: WP-CLI provides commands for importing and exporting content from your WordPress site.
  6. Database Management: You can perform various database operations such as optimizing, repairing, and searching the database.
  7. Performing Maintenance Tasks: WP-CLI allows you to perform various maintenance tasks such as generating thumbnails, cleaning up the database, and more.
  8. Developing and Debugging: It provides tools for developers to scaffold plugins and themes, run unit tests, and debug WordPress sites.

Using WP-CLI can significantly speed up your WordPress development and maintenance tasks, especially for tasks that would otherwise require navigating through the WordPress admin interface. It’s especially useful for developers and administrators who are comfortable working in a command-line environment.


WPCLI installed

Create child theme

wp scaffold child-theme sample-theme --parent_theme=twentysixteen

Database commands

Delete database

This command drops the database. No name is required as wpcli looks in the wp-config file to find the database name. You can run this command from anywhere within your Wordpress file structure.

wp db drop

Export database

Will export an SQL file to your Wordpress root directory.

wp db export

Import database

Ensure to provide the correct path to the file.

wp db import wordpress_dbase.sql

Search and Replace database

Find all occurences of a string in a database and replace it with another value. This can be really useful when you are migrating a site to a different domain.

wp search-replace 'http://example.test' ''

Plugin commands

List plugins

wp plugin list

Delete plugin

wp plugin delete akismet

Install Plugin

Here we install the query monitor plugin

wp plugin install query-monitor

Update All Plugins

wp plugin update --all

Update WP Core

wp core update
wp rewrite flush

User commands

Create a wp user account

wp user create bob --role=author

Get the ID of the user

This command is important for running other user related functions that take the user id as a requirement.

wp user list

Update the password of the user

Once you have the user ID then you can update the users password

wp user update 7 --user_pass=new_pass

Generate posts

Generate dummy / demo content

wp post generate --count=10 --post_type=page --post_date=1999-01-04

Regenerate Image sizes

As you may already know Wordpress supports custom image sizes. Now when you add a new custom image size your site, you will need to regenerate the images so that your new custom image files in the new size exists.

wp media regenerate --image_size=large


If you are getting some errors when trying to update plugins it could be due to permissions. Some plugins also require a valid license to update.

To fix a permission related issue. See the link below to reset the Wordpress file and directory permissions.

see wp file permissions commands

Switch to non root user

If you have installed WpCLI on a webserver. Before running any wpcli commands you probably want to switch to a non-root so that you are not flagged with warnings when running these commands as root.

Switch to non-root user

su non-root

Install WordPress with WpCLI

WpCLI Plays an important role when you installing WordPress on a barebones VPS. As there is no control panel there is no user interface for creating and installing the database. WpCLI steps into to help out and makes installation of Wordpress on a barebones VPS efficient and easy.

Install WordPress website on a VPS using WPCli

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.