WordPress

How to Manage WordPress Themes from the Command Line with WP-CLI

wordpress themes
Written by Caleb Boylan

In this series of blog posts, we will cover the basic but useful tasks WP-CLI has to offer, such as upgrading WordPress core and managing your plugins. By the end of the series, you’ll be comfortable using WP-CLI and discovering even more ways you can use it to simplify your life!

wordpress themes

WP-CLI can be used to manage themes in a similar way it can be used to manage plugins—it can install, enable, update, and much more, all from the command line. Keeping your plugins up to date is essential, as an out-of-date plugin could potentially have security issues fixed in a newer version. To start off, use the following command to see all the things you can do to your themes using WP-CLI by running:

[user@server]$ wp help theme

This will show you a man page-like help description.

The first step to being able to manage your themes from the command line is being able to list what themes you have installed and their statuses. WP-CLI makes this extremely simple:

[user@server]$ wp theme list

Now if you wish to install a theme, the first step in doing that is to search for the theme using WP-CLI:

[user@server]$ wp theme search <term>

For example:

[user@server]$ wp theme search illdy

+-------+-------+--------+

| name  | slug  | rating |

+-------+-------+--------+

| Illdy | illdy | 96     |

+-------+-------+--------+

This returns a list of themes that match the search term you provided, as well as the word you can use to install it (slug), and a rating. You can customize the fields it shows you by using the –fields= flag, including adding a URL to view an example of the theme (take a look at the help for more info on how to do this). When you find a theme you want to install, you can install it using WP-CLI as well:

[user@server]$ wp theme install <slug>

This downloads the theme and installs it in the proper directory for use. Finally, you must activate your new theme if you want to enable it:

[user@server]$ wp theme activate <slug>

After running this command, your site will start using the new theme you just activated. Voila!

In the next episode, we’ll show you some extra WP-CLI commands that can be useful for running your website and debugging issues. Stay tuned!

Have questions? Hit up our support team or tweet us @DreamHostCare on Twitter! 

About the author

Caleb Boylan

Caleb is the Developer Advocate for the Corporate Communications team at DreamHost.