Help Docs Content Management Systems (CMS) WordPress Overview Managing Themes and Plugins With WP-CLI

Managing Themes and Plugins With WP-CLI

Master WP-CLI to manage your WordPress site. Learn commands to list, install, update, and delete plugins and themes directly from the command line.

WP-CLI allows you to interact with plugins and themes right from the command line. This is one of the most useful actions of this tool. You can list out-dated plugins, pause them, delete them, or update them with just a few commands.

Depending on your need, follow the links below to navigate to the correct section:
Modifying Plugins
Modifying Themes

Warning:

Because WP-CLI relies on the wp-config.php to query your database, it is important to take a backup of your database before making any changes to your site. You can take a backup through your Managed WordPress Portal or through FTP/SFTP. See our article below for instructions:
Taking a Manual Backup with FTP/SFTP

Modifying Plugins

Note:

When modifying a plugin or theme, you will use the plugin or theme slug. These can be found in the WordPress Codex. If a theme or plugin is not in the WordPress repo, this method will not work.

Activate and Disable Plugins

Warning:

While you can activate or update all plugins and themes at once, this is not best practice as any conflicts with updates could have negative consequences to your site. If you do decide to use this command, use the –dry-run flag to run first to make sure no issues arise from the updates.
  • List Plugins – You can run a command to list all of your plugins and check versions and statuses:
    s56@default:~/html$ wp plugin list 
    +------------------------+----------+-----------+------------+
    | name                   | status   | update    | version    |
    +------------------------+----------+-----------+------------+
    | akismet                | active   | none      | 4.0        |
    | async-javascript       | inactive | none      | 2.17.06.13 |
    | autoptimize            | inactive | none      | 2.2.2      |
    | bj-lazy-load           | inactive | available | 1.0.8      |
    | tiny-compress-images   | inactive | available | 2.2.3      |
    | hello                  | inactive | none      | 1.6        |
    | ithemes-sync           | active   | none      | 2.0.0      |
    | lazy-load-for-comments | inactive | none      | 1.0.3      |
    | w3-total-cache         | active   | none      | 0.9.5.4    |
    | woocommerce            | active   | none      | 3.1.2      |
    | woocommerce-services   | active   | none      | 1.7.0      |
    | wordfence              | inactive | available | 1.1        |
    +------------------------+----------+-----------+------------+
  • List Active Plugins –  List only active plugins:
    wp plugin list | awk '$2 == "active" {print $l}'
    
  • List Inactive Plugins – List only inactive plugins:
    wp plugin list |awk '$2 == "inactive" {print $l}'
  • Disable Plugins –  You can disable an individual plugin or all plugins:
    • Disable Individual Plugin:
      wp plugin deactivate $PLUGIN_SLUG_NAME
    • Disable All Plugins:
      wp plugin deactivate --all
  • Activating Plugins – You can activate an individual plugin or activate all plugins.
    • Activate Individual Plugin:
      wp plugin activate $PLUGIN_SLUG_NAME
      
    • Activate All Plugins:
      wp plugin activate --all

Updating Plugins

Note:

Before updating a plugin, you can use the –dry-run flag which will give you a sample output so you can preview changes before you run the update live.
  • Show Outdated Plugins – Passing the –field flag to update, you can specify plugins that are not recently updated. Run the following command:
    wp plugin list --update=available

    Example output:

s56@default:~/html$ wp plugin list --update=available
+----------------------+----------+-----------+---------+
| name                 | status   | update    | version |
+----------------------+----------+-----------+---------+
| bj-lazy-load         | inactive | available | 1.0.8   |
| tiny-compress-images | inactive | available | 2.2.3   |
| wordfence            | inactive | available | 1.1     |
+----------------------+----------+-----------+---------+
  • Update a Plugin – To update a plugin that’s out of date, just run the command:
    wp plugin update PLUGIN_SLUG_NAME
    

    Example output:

    s56@default:~/html$ wp plugin list --update=available
    +----------------------+----------+-----------+---------+
    | name                 | status   | update    | version |
    +----------------------+----------+-----------+---------+
    | bj-lazy-load         | inactive | available | 1.0.8   |
    | tiny-compress-images | inactive | available | 2.2.3   |
    | contact-form-7       | inactive | available | 1.1     |
    | wordfence            | inactive | available | 1.1     |
    +----------------------+----------+-----------+---------+
    
    

    Updated (the URL shown is subject to change based on the version of the update):

    s56@default:~/html$ wp plugin update wordfence
    Downloading update from https://downloads.wordpress.org/plugin/wordfence.6.3.19.zip...
    Unpacking the update...
    Installing the latest version...
    Removing the old version of the plugin...
    Plugin updated successfully.
    +-----------+-------------+-------------+---------+
    | name      | old_version | new_version | status  |
    +-----------+-------------+-------------+---------+
    | wordfence | 1.1         | 6.3.19      | Updated |
    +-----------+-------------+-------------+---------+
    Success: Updated 1 of 1 plugins.
    

    Note:

    Updating a plugin will only work if an update is available from the repo. If it’s a custom plugin, WP-CLI won’t know if there’s an update or not because it isn’t querying from the proper source.
  • Delete a Plugin – If you have a plugin you’re no longer using and is inactive, you can delete it from WP-CLI.
    wp plugin delete PLUGIN_SLUG_NAME

    Warning:

    Deleting a plugin is permanent, any data connected with it will be deleted as well. Run a backup as a safety measure.
  • Install a Plugin – You can install any plugin as long as it’s in the WordPress plugin repo at: https://wordpress.org/plugins/. The command structure is:
    wp plugin install $PLUGIN_SLUG_NAME

Example:

Say I want to install Jetpack on my WordPress site. I would find the repo at https://wordpress.org/plugins/jetpack/ and then run the following command and get the corresponding output (note that the URL in the output could be different than the one shown below depending on the version numbers involved):

s56@default:~/html$ wp plugin install jetpack
Installing Jetpack by WordPress.com (5.3)
Downloading install package from https://downloads.wordpress.org/plugin/jetpack.5.3.zip...
Unpacking the package...
Installing the plugin...
Plugin installed successfully.
Success: Installed 1 of 1 plugins.

Modifying Themes

Just like with plugins, you can install and modify themes. As long as the theme is in the WordPress repo, it can be installed through WP-CLI. You can search the theme repo here: https://wordpress.org/themes. Installing themes with WP-CLI takes less time than going to your WordPress admin panel as it connects the server directly to the WordPress theme repository and imports them in just a few seconds. This can be valuable for troubleshooting purposes.

  • Installing Themes – To install a theme, use the following command:
    wp theme install $THEME_SLUG_NAME
  • Activating Themes –  Once you install a theme, you need to activate it:
    wp theme activate $THEME_SLUG_NAME
  • Updating Themes – If you have a theme already installed, but needing an update, run the following command:
    wp theme update $THEME_SLUG_NAME

    You can also update all themes:

    wp theme update --all

    Warning:

    While you can activate or update all plugins and themes at once, this is not best practice as any conflicts with updates could have negative consequences to your site. If you do decide to use this command, use the –dry-run flag to run first to make sure no issues arise from the updates.
  • Check Site URL – Print the site URL from the WordPress install:
    wp option get siteurl
Was this article helpful?