Skip to content

Instantly share code, notes, and snippets.

@bigdawggi
Last active February 16, 2023 05:54
Show Gist options
  • Save bigdawggi/9079774 to your computer and use it in GitHub Desktop.
Save bigdawggi/9079774 to your computer and use it in GitHub Desktop.
WP-CLI commands to get the active themes across a WordPress blog network (single site ID with multiple blogs for the site)
# Be sure to change or omit the --network parameter; it defaults to 1.
wp site list --network=4 --field=url | while read line; do wp theme list --status=active --field=name --url=$line >> /tmp/wpcli-themes.txt; done && sort /tmp/wpcli-themes.txt | uniq -c
@bigdawggi
Copy link
Author

Note this is not supposed to be a bash file, but instead just a copy and paste into the bash cli

@iandunn
Copy link

iandunn commented May 28, 2021

Thanks for sharing this!

I found it to take 20+ minutes on a network with 1300 sites, though. It may be possible to optimize with an approach similar to wp plugin active-on-sites. That would avoid the overhead from launching WP-CLI and reading from disk N times, and takes about 65 seconds on the same network.

These is the wp find-unused-themes package, but it's also pretty slow because it relies on WP_CLI::launch_self.

@bigdawggi
Copy link
Author

Thanks @iandunn, if I ever need this again, I'll investigate it :)

@emrikol
Copy link

emrikol commented Jan 13, 2022

I think using something like wp option get stylesheet --url="$line" should go much faster than wp theme list

@iandunn
Copy link

iandunn commented Jan 13, 2022

wp find-unused-themes fixed the performance issue, so it's a good solution now IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment