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.


wp

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

amazon prime gift

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

amazon prime gift

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 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
WordPress plugin development: How to fix a SQL injection?WordPressWhat is the difference between let and var in Swift?SwiftAlways add associated labels to your Form elementsUI/UXHow to get front page or home page ID in WordPress?WordPressJavaScript arrays: a separate data type or Objects?JavaScriptGive buttons accessible namesUI/UX