WP-CLI » Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

The principle of WPCLI is to add install it on the server, add it to path so that it can be accessed from any folder and then enter the installation folder of the website for which you want to run commands.

The basic use of WP-CLI is: wp [COMMAND], e.g. wp config list will show you the content of wp-config.php file without any comments (lines that start with /* ):

wp config list
image - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors
wp config list

Plugin setup is much simpler with WP-CLI, for example, to install and activate the Akismet plugin:

wp plugin install akismet --activate
image 1 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors
wp plugin install akismet –activate

To install multiple plugins at once:

wp plugin install advanced-custom-fields jetpack akismet --activate

To check if plugin is active or inactive run wp plugin status

wp plugin status
image 2 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors
wp plugin status

To update plugins wp plugin update name-of-the-plugin, for example:

wp plugin update akismet

or to update all plugins:

wp plugin update --all
image 3 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors
(Yes I keep all my plugins up to date, as should you!)

Another handy command is skip-plugins, which allows you to temporarily disable plugins and load WordPress without them.

wp --skip-plugins=akismet

and to temporary disable all active plugins at once:

--wp plugin list --field=name --status=active --skip-plugins | xargs -n1 -I %

Show installed themes summary and various states:

wp theme list
image 5 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

To install and activate theme, copy it’s URL slug from the wp.org theme repository.

image 4 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors
wp theme install twentytwentyone --activate
instaliranje teme iz wpcli - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

To create a child theme

wp child-theme FOLDER-NAME --parent_theme=PARENT-THEME-FOLDER --theme_name=CHILD-THEME-NAME

Here are a few more commands to activate, delete and update themes.

wp theme activate THEMENAME
wp theme update THEMENAME
wp theme delete THEMENAME

You can find more information in the official WP-CLI documentation.


To list users:

wp user list
image 13 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

To create a new admin user, and auto-generate a password, use:

wp user create username [email protected] --role=administrator
image 11 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

Or to add a custom password use –user_pass=

wp user create username [email protected] --role=administrator --user_pass=3fg62g6732rg32
image - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

To change user password

wp user update USERNAME --user_pass=NEW_PASS
image 12 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

Delete a user and reassign all content from that user to the admin user:

wp user delete [email protected] --reassign=1
image 1 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

wp db allows you to performs basic database operations using credentials stored in wp-config.php, for example to open a MySQL console using credentials from wp-config.php run:

wp db cli
image 10 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

To export database use:

wp db export
image 14 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors
wp db optimize
image 6 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors
wp db repair
image 7 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

I find wp db quite useful when you need to drop and import tables in database:


Here are some of the most common WP-CLI errors that Ive personally encountered so far:

Error: This does not seem to be a WordPress installation.

Enter the folder with your WP installation.

pwd – check in which directory you are currently, then to enter the right directory use cd /some/dir/wp/

image 8 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

greska2 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

wp is not added to your path, to workaround this, make sure to use the full path to the downloaded wp-cli.phar file

/home/USERNAME/public_html/wp-cli.phar

lf you are using W3TC plugin along with WP-CLI, you may notice the following error.

image 9 - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

To fix this, before running any wpcli commands rename the wp-content/object-cache.php file


This is a well known bug on actual WP-CLI versions that is related to the Unicode BOM inside the wp-config.php file. To fix it, simply open the wp-config.php file and remove the code from the beginning:

chrome 9rqpXbEUzo - Most useful WP-CLI commands with examples + how to fix most common WPCLI errors

Was this post helpful?

Leave a Comment

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Recommended