A screenshot of the script used to download and install all block-based themes.

Installing Block-based themes with WPCLI

After some of the great sessions at WordCamp US, I was inspired to learn more about some of the block-based themes found on WordPress.org.

The quickest way to view the published block-based themes is to browse the “Full site editing” tag of themes on WordPress.org.

But what if we want a way to quickly download and browse the code of those themes on our own machine?

Listing WordPress themes from the CLI

Examining the requests made from the above page, I noticed that the main content is generated from the response to a call to the /themes/info endpoint of api.wordpress.org.

A screenshot of investigating the requests made by api.wordpress.org

Exploring that endpoint a bit with restclient.el package in Emacs showed that there’s an easy way to get the theme slugs!

A screenshot of exploring the api.wordpress.org/themes/info endpoint.

Install all Block-themes with curl, jq, and wpcli

So we have a URL, and if we have jq installed, then we can pipe our way to installing all of the block-themes!

curl https://api.wordpress.org/themes/info/1.2/\?action\=query_themes\&request%5Btag%5D%5B%5D\=full-site-editing\&request%5Bper_page%5D\=50 | jq -r '.themes[].slug' | xargs wp theme install
A screenshot of the script used to download and install all block-based themes.

Once those are downloaded, it’s just a matter of listing the themes and activating one!

A screenshot of activating and listing the themes using WPCLI.

Posted

in

by

Tags: