I thought retrieving the currently active theme on a WordPress website with WP CLI would involve the wp theme command but I was wrong. The correct command to get the currently active theme is wp option get current_theme.
Example
$ wp option get current_theme
Bootstrap4 Genesis
What You Can Get from wp theme
When we run wp theme list
+----------------------+----------+--------+---------+----------------+-------------+
| name | status | update | version | update_version | auto_update |
+----------------------+----------+--------+---------+----------------+-------------+
| bootstrap4-genesis | active | none | 1.3.2 | | off |
| genesis | parent | none | 3.5.0 | | off |
| twentytwentyfour | inactive | none | 1.2 | | off |
+----------------------+----------+--------+---------+----------------+-------------+
We can see the active theme but it isn’t easy to grab it programmatically (though we can grab it by setting the output to json and using the jq utility, see following example).
Thanks for calling this out Ryan Neilson.
Alternative Command to Retrieve Current Theme
wp theme list --status=active --format=json | jq '.[0].name'
Get List of Active Themes in a WordPress Multisite
This is a helpful command based on Loop Through WordPress Multisite Blogs with WP CLI to display all of the site names and the active theme on that site.
for URL in $(wp site list --field=url); do
wp option get blogname --url=$URL;
wp option get current_theme --url=$URL;
echo "-----------------------------";
done
You could use `wp theme list –status=active –field=title`, no?
Thanks Felipe!
You’re right, both
to get the title and
to get the name (i.e. the same value I was getting with
wp option get current_theme) work!I’ll need to update this article.
Thank you!