Currently Available: Need a skilled Software Developer for your next project?
Categories
WordPress

Managing WordPress Themes and Plugins with WP-CLI

When you manage a WordPress site from a terminal, WP-CLI lets you inspect, install, update, activate, and remove themes and plugins with commands. WP-CLI is WordPress’s command-line interface: it runs site-administration tasks against the WordPress files and database you select.

The commands are straightforward, but the target matters. A command aimed at the wrong installation or multisite site changes the wrong place. Confirm the target, review what is installed, and make a restorable backup before changing a live site. The examples below show how to manage extensions while keeping those checks part of the work.

Confirm the WordPress site first

WP-CLI uses the current directory to find WordPress, or you can select an installation with the global --path option. Run a few read-only commands before making changes:

cd /path/to/wordpress
wp --info
wp core version
wp plugin list
wp theme list

wp --info reports details about the WP-CLI environment, including the PHP executable it uses. wp core version confirms the WordPress version in the selected installation. The plugin and theme lists show what is installed and help catch an incorrect target before a command changes anything.

For a multisite installation, which hosts multiple WordPress sites in one installation, add --url to select a site:

wp plugin list --url=https://site.example.com/

Use --path=/path/to/wordpress when you are not in the WordPress directory. WP-CLI documents these global parameters, including remote execution options.

The plugin inventory can include status, installed version, available update version, and auto-update status. For a script or report, choose a structured format or specific fields:

wp plugin list --format=json
wp plugin list --fields=name,status,version,update,update_version,auto_update

The available formats and fields are documented in the wp plugin list reference. The theme command group also includes commands for listing themes and checking a theme’s status or details.

Install from a WordPress.org slug or ZIP file

A plugin or theme slug is its directory identifier on WordPress.org. Use the slug to install from the WordPress.org directory, or provide a path or URL to a ZIP archive for packages distributed elsewhere.

# Install a plugin from WordPress.org
wp plugin install plugin-slug

# Install a plugin from a local ZIP
wp plugin install ../plugin-package.zip

# Install a theme from WordPress.org
wp theme install theme-slug

# Install a theme from a local ZIP
wp theme install ../theme-package.zip

Installation does not activate an extension unless you request activation. Add --activate to an installation command when you intend to enable the plugin or switch the site to the theme immediately:

wp plugin install plugin-slug --activate
wp theme install theme-slug --activate

For a multisite network, --activate-network requests network activation for a plugin. That affects the network rather than just one site, so use it only when network-wide activation is intended.

The plugin install command and theme install command document accepted package sources and options such as requesting a specific WordPress.org version. A ZIP path or URL only tells WP-CLI where to get a package; it does not establish that the package is trustworthy or compatible with your WordPress and PHP versions.

Avoid using --insecure as a routine response to a failed download. WP-CLI warns that this option retries without certificate validation, leaving the download vulnerable to a man-in-the-middle attack.

Activate and deactivate extensions

Activation controls whether WordPress uses an installed extension. A plugin can remain installed while inactive; activating a theme changes the theme used by the site.

wp plugin activate plugin-slug
wp plugin deactivate plugin-slug

wp theme activate theme-slug

Before activating a theme on a live site, confirm that the switch is intended and that you can restore the previous state if the site does not work as expected. For a networked installation, distinguish site-level plugin activation from network activation, and use the target site’s --url when the command should apply to only one site.

Preview and apply updates

Update a named extension when you want to limit the change. To update all eligible plugins or themes, preview the changes first with --dry-run:

# Preview updates
wp plugin update --all --dry-run
wp theme update --all --dry-run

# Apply updates after reviewing the preview
wp plugin update --all
wp theme update --all

The preview helps you see which extensions WP-CLI would update. It does not test compatibility or guarantee that the site will work afterward. For a live site, make sure you can restore both the database and the files before applying updates, then check important pages and functions after the commands finish.

WP-CLI also supports updating a specific extension:

wp plugin update plugin-slug
wp theme update theme-slug

The plugin update reference and theme update reference document bulk-update controls and filters. Some options are version-dependent, so check the live command reference before adding a flag to a script.

A database export provides a copy of database contents, but it does not include theme or plugin files. For example:

wp db export before-extension-updates.sql

The wp db export command writes a SQL export. Pair it with a backup of the relevant WordPress files and verify that you can restore both; otherwise, you do not have a complete rollback plan.

Remove a plugin without confusing deletion and uninstalling

Deactivating a plugin leaves its files in place. Deleting and uninstalling perform different actions, so choose based on whether you want to run the plugin’s cleanup routine.

# Stop using the plugin but keep its files
wp plugin deactivate plugin-slug

# Run the uninstall procedure and remove the plugin
wp plugin uninstall plugin-slug

# Deactivate first, then uninstall
wp plugin uninstall plugin-slug --deactivate

The uninstall command runs the plugin’s uninstall procedure. What that procedure does to stored data depends on the plugin, so check its documentation before removing it if you need to preserve plugin-specific settings or content. The wp plugin uninstall reference describes the command behavior.

The wp plugin delete command removes plugin files without deactivating or uninstalling the plugin. Use uninstall when you intend to run the plugin’s cleanup procedure; use deletion only when that is the action you want.

Handle multisite and command failures carefully

In multisite, --url selects the site for a site-specific command. For example:

wp theme list --url=https://site.example.com/
wp plugin list --url=https://site.example.com/

Network activation is a separate decision from activation on one site. Check the command reference and confirm the target before running a network-wide change. If you automate commands across a network, test the shell command on a small scope first; shell syntax and behavior depend on the environment.

If a plugin or theme prevents WP-CLI from loading normally, the global --skip-plugins and --skip-themes options can help troubleshoot. These options do not skip must-use plugins, which can still affect the command. Check wp --info as well if a command behaves differently from the website: WP-CLI uses a command-line PHP environment that can differ from the PHP used by the web server. The installation handbook explains how to inspect the WP-CLI setup.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

Your email address will not be published. Required fields are marked *