Using WP-CLI To Create An _s-Based Theme

I’ve been playing around with WP-CLI, a tool to manage WordPress by command-line, a lot lately and one of my favorite parts of it is the things that it can do with themes.

Currently there are two well-known ways of building a theme with _s:

  1. Manual: Clone the _s GitHub repository directly into /wp-content/themes/ and go through the steps of renaming text domains, function names, DocBlocks, and prefixed handles
  2. Automatic: Go to underscores.me, enter a desired theme name and advanced options (optional), generate a theme, download the theme, unzip the theme, and put it into /wp-content/themes/

I prefer the manual approach because I’m an active contributor and committer to _s and working with Git and command-line text replacement feels natural to me. Plus, I like a bit of control.

It is tedious, though, and WP-CLI introduces a new way of kicking off an _s-based theme that molds the above two approaches into one delightful solution.

Here’s how to do it.

  1. Install WP-CLI. It’s incredibly painless.
  2. From within the WordPress install directory run the following command: wp scaffold _s theme-slug --theme_name="The PAM Theme" --author="Philip Arthur Moore" --author_uri="https://philiparthurmoore.com/"
  3. That’s it!

You’ll of course need to replace my values with yours, but otherwise that’s really all there is to it. Once you’re done with the above two steps then you can happily navigate to wp-content/themes/theme-slug and get to work.

The added benefit of this approach is all the additional goodies that come with WP-CLI. If you’re a theme builder, study the theme list and integrate it into your workflow. It’ll make common actions like switching themes and checking theme paths feel so much quicker.

Author: Philip Arthur Moore

CEO at We Cobble. We build digital products for people.™

Discover more from Philip Arthur Moore

Subscribe now to keep reading and get access to the full archive.

Continue reading