Yogesh Chauhan's Blog

A list of wp-cli commands to use via SSH

in WordPress on May 9, 2021

WordPress Command Line Interface = wp-cli

You can use command-line tool with any of your servers. They usually comes with your server setup. All you need to do is add/activate SSH users for your server and then you can run WordPress commands using your terminal app. You can make changes to database and plugins just using the terminal, without even going to the server dashboard.

Basic wp-cli commands

View all commands

This will show all wp-cli commands list.


Get help for a specific command

wp plugin --help

Get wp-cli version

wp cli version

Check for wp-cli updates

wp cli check-update

Update wp-cli

wp cli update

wp-cli commands for plugins

View installed plugins

wp plugin list

Install a plugin

wp plugin install plugin-name

Activate a plugin

wp plugin activate plugin-name

Deactivate a plugin

wp plugin deactivate plugin-name

Activate or Deactivate (toggle plugin status) a plugin

wp plugin toggle plugin-name

wp-cli commands for themes

View all installed themes

wp theme list

Install a new theme

wp theme install theme-name

Activate any installed theme

wp theme activate theme-name

Update an installed theme

wp theme update theme-name

wp-cli commands for WordPress

Check the current core WordPress version

wp core version

Check if core WordPress updates are available

wp core check-update

Update code WordPress

wp core update

Force download and overwrite core WordPress files

wp core download --force

wp-cli commands for WordPress users

View all current users

wp user list

Create a new user

This will create a new user with an email address and a role. A temporary password will be printed in return of the command.

wp user create enter-username [email protected] --role=administrator

Change a password using user ID number

If you’re not sure about the user ID number then you can get the users list.

wp user update 11 --user_pass=enter new password

In the example above, 11 is the user ID number.

Delete a user

Deleting user requires a user ID as well.

If you’re not sure about the user ID number then you can get the users list.

When you delete a user, you need to reassign that user’s posts to another user so those posts are not permanently deleted.

wp user delete 10 --reassign=1

wp-cli commands for cache management

Flush website cache

wp cache flush

Clear the wp-cli cache

wp cli cache clear

wp rewrite flush

wp-cli commands for database management

Check the database status

wp db check

Optimize the database

wp db optimize

Repair the database

wp db repair

Search the database for a specific string

wp db search yogesh

Update the database to the latest version available

wp core update-db

Search and replace a string in the database

wp search-replace https://yogeshchauhan.com https://yogeshchauhan.com/blog

Make sure you run the search and replace command above with a –dry-run flag. It will show you what will change and in which tables.

Search and replace with a –dry-run flag

wp search-replace https://yogeshchauhan.com https://yogeshchauhan.com/blog --dry-run

wp-cli commands for home and siteurl

View home and siteurl

wp option list | grep -E "^(siteurl|home)"

Update the home url

wp option update home https://yogeshchauhan.com

Update the siteurl

wp option update siteurl https://yogeshchauhan.com

wp-cli commands for wp-config.php file

View all settings in wp-config.php file

wp config list

Update a setting in wp-config.php file

wp config set DB_NAME local

wp config set DB_USER root

Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
How to disable scrolling on html body on menu click using JavaScript?JavaScriptFilling a button background from left to right using CSSCSSRendering Elements in ReactReactActions vs. Filters: hooks in WordPressWordPressHow to make HTML form interactive and using CSS?CSSHow to get the first element with a class name xyz using JavaScript?JavaScript