WP-CLI Commands for Beginners

In this tutorial we will take a look at the WP CLI, the WordPress Command Line Interface. Using this tool you can perform many functions to manage WordPress; Normally you would use the WP  admin or by adding various plugins to do the same things.  This is primarily for users to like to work in the the command line to manage software. However this can be helpful for certain situations for anyone and can also be a time saver if you setup many WordPress websites. We’ll take a look at 5 uses of the WP CLI in this video.

Backup before you attempt these commands on a Production / Live website!

SETUP

Bitnami WordPress instances already include the wp-cli. To check if you have it, simply open the SSH terminal to your instance and type the following command in your terminal window:

sudo wp cli version

If it comes back with a version then you’re good. I’m currently on the latest version 2.5 and if you have an older version than this, just run:

sudo wp cli update

If you don’t have wp cli installed, this is a link the guide for installing it:

https://make.wordpress.org/cli/handbook/guides/installing/

If you run into issues using wp cli or have any errors refer to these links:

https://make.wordpress.org/cli/handbook/guides/identify-plugin-theme-conflict/

https://make.wordpress.org/cli/handbook/guides/troubleshooting/

COMMANDS

1. List Scheduled WP Events

If you want to see the list of scheduled events that are running for WordPress, typicall you have to install a plugin for it; but you can run this command to see the list.

sudo wp cron event list

You can also manage cron events with this command. see this for more

https://developer.wordpress.org/cli/commands/cron/

2. Change Your Password

If you find yourself locked out due to losing the password. You can try to use the reset password via email but if that fails or you wan to quickly do it via command line, to update the password run this command;

sudo wp user update email_address  --user_pass=USE_STRONG_PASSWORD

3. Install & Activate common plugins

If you start your wordpress site with common set of plugins like the top 5 plugins video I made. Then you can do that with a single command line.  For example I want to install wordfence firewall, wp forms smtp plugin and a plugin that disables comments feature. I would run this command:

sudo wp plugin install wordfence wp-mail-smtp disable-comments --activate

This installs and activates the plugins. The plugin names from the WordPress plugin repo name as shown here

https://wordpress.org/plugins/disable-comments/

If you activated a plugin and you aren’t able to get into wp-admin again due to some error, use this to deactivate plugin

sudo wp plugin deactivate plugin_name

4. Generate Dummy Content

content=$(curl -Ns https://loripsum.net/api/5)
echo $content | wp post generate --post_content --count=10  <-- put the number of posts you want to create.

5. Database Search & Replace

If you want to replace a string of text within the content tables of WordPress then use this command. Common scenario is to replace URLs when changing domains for a website. So to do this run following:

sudo wp search-replace  'old_url' 'new_url' --skip-columns=guid --dry-run

Remove –dry-run to apply the change permanently. (remember to backup before running this command)

If you use the elementor plugin to build pages, then you need to run this command additionally

wp elementor replace-urls 'old_url' 'new_url'

List of all available commands.

https://developer.wordpress.org/cli/commands/

All videos tutorials on the website as well as the YouTube channel aim to provide a simplified process for a specific scenario; there could be many different factors and unique use cases you may have. The tutorials may not cover every situation; so treat is as a starting point or learning concept to apply to your unique situations, and consider this inspiration but not prescription or explicit direction.

Scroll to Top