WP-CLI lets you manage WordPress from the command line. Powered Cache Premium adds the wp powered-cache command, so you can clear the cache, warm it and generate CSS from scripts, deployment pipelines or cron jobs, without opening the admin.
Available in: Powered Cache Premium
Where to find it: the command line of your server: wp powered-cache <subcommand>
Requires: WP-CLI, and Powered Cache and Powered Cache Premium active. criticalcss and ucss also need an active license.
| Subcommand | What it does |
|---|---|
purge | Clears all cache files and the object cache, or the cache of one post. |
preload | Runs a full cache preload in the foreground and reports the result. |
varnish | Sends a purge request for one URL to Varnish. |
criticalcss | Generates or clears Critical CSS. |
ucss | Generates or clears used CSS for Remove Unused CSS. |
Run the commands as the same system user that runs your web server, so new cache files get the right owner. On multisite, add WP-CLI’s global --url=<site address> option to target a specific site.
purge #
wp powered-cache purge [--post_id=<id>]
| Option | Description |
|---|---|
--post_id=<id> | Clears the cache of one post: the post itself and the pages that list it, such as the home page and its archives, just like when you update the post. Prints a warning if the post is not published. |
Without --post_id, the command empties the object cache and deletes the whole wp-content/cache/ folder. That includes the page cache of every site on a multisite network, minified files, Critical CSS, used CSS and locally hosted tracking scripts, which are created again when needed. Cloudflare is purged too when the Cloudflare integration is on.
Unlike Purge All Cache in the admin, the command does not purge Sucuri or Varnish and does not start a preload. Run wp powered-cache preload afterwards if you need warm pages.
# Clear everything
wp powered-cache purge
# Clear the cache of post 123
wp powered-cache purge --post_id=123
preload #
wp powered-cache preload [--homepage] [--post] [--taxonomy] [--limit=<number>] [--interval=<seconds>] [--force] [--lang=<code>] [--network-wide]
Runs a full cache preload in your terminal. It checks every URL from the selected sources and preloads the pages that are not cached yet. Every public post and non-empty archive is included, without the 1,000-post and 100-term limits of automatic preloads. Pages skipped earlier, for example redirects or missing pages, are checked again.
The command works even when the Cache Preload setting is off. Page caching must be on. Otherwise it stops with Preload does not help when page caching disabled.
| Option | Description |
|---|---|
--homepage | Preload the home page. |
--post | Preload public posts, pages and custom post types. |
--taxonomy | Preload public category, tag and other archive pages. |
--limit=<number> | Preload at most this many posts, newest first, and at most this many archives per taxonomy, starting with those that have the most posts. |
--interval=<seconds> | Seconds to wait between requests for this run. 0 means no wait. Without it, your Preload Speed setting applies. |
--force | Delete the page cache of the site first, stop any preload already running, then preload everything again. |
--lang=<code> | On WPML sites, preload only this language, for example --lang=es. all or no value preloads every language. |
--network-wide | On multisite, cover the whole network. See Multisite. |
Sources: without any of --homepage, --post or --taxonomy, the command uses your saved preload sources, including Additional Preload URLs and, with Premium, sitemaps. If you pass at least one of these flags, only the flagged sources are used, and Additional Preload URLs and sitemaps are skipped.
Progress and summary: the command prints a progress line about every 50 URLs and ends with a summary of the results. Pages are found and preloaded in batches, so until every page has been found, the total is an estimate (about). After that, the exact total is shown. On multisite networks the progress lines show the URLs checked and the URLs waiting in the current batch instead.
Checked 50 of about 262 URLs.
Checked 100 of about 262 URLs.
…
Checked 250 of 258 URLs.
Success: Preload finished. 258 URLs checked (warmed: 240, cached: 18, …).
warmed counts pages preloaded in this run and cached pages that were already cached. The other counts are the reasons pages were not preloaded, as explained in Why a page is not preloaded.
While it runs: the daily scheduled preload, Preload all pages now and the admin bar Preload Cache command do not start a second run on top of it. A second wp powered-cache preload, for example from an overlapping cron job, stops with Another WP-CLI preload is already running. Add --force to stop the running preload and start again.
Stopping it: if you press Ctrl+C or close the terminal, the preload stops right away and you can run the command again. If the process is killed without warning, for example by the server, the next command can start after about three minutes. Pages that were already preloaded count as cached, so the next run goes quickly.
--force safety check: before deleting anything, --force checks that the preload URL table exists. If it does not, the command stops with The preload URL table is not available, so the page cache was not cleared. and your cache stays in place.
# Preload the configured sources
wp powered-cache preload
# Rebuild the whole page cache after a deployment
wp powered-cache preload --force
# Only the home page and the 200 newest posts, one second apart
wp powered-cache preload --homepage --post --limit=200 --interval=1
# Only the Spanish pages of a WPML site
wp powered-cache preload --lang=es
Changed in 4.1:
preloadruns the same full preload as the admin and shows progress and a summary. Scheduled, on-demand and other WP-CLI preloads do not start while it runs. Without source flags it uses your saved sources, even when Cache Preload is off.
varnish #
wp powered-cache varnish --purge=<url> [--regex]
| Option | Description |
|---|---|
--purge=<url> | The URL to purge. A trailing slash is added. |
--regex | Purge the URL and everything below it, by sending X-Purge-Method: regex. |
The command sends one PURGE request and prints Varnish purge request sent for: …. It does not report whether Varnish accepted it. The request goes to the address in the VHP_VARNISH_IP constant if you defined one, otherwise to the host in the URL. In 4.1 it does not use the Varnish IP Addresses setting. See Varnish Integration.
# Purge one page
wp powered-cache varnish --purge="https://example.com/sample-page/"
# Purge the whole site
wp powered-cache varnish --purge="https://example.com" --regex
criticalcss #
wp powered-cache criticalcss [--generate] [--clear] [--network-wide]
| Option | Description |
|---|---|
--generate | Generate Critical CSS in the foreground for the sample URLs of each page type (front page, posts page, archives, single posts and so on). Page types that already have Critical CSS are skipped. With Separate Mobile Cache on, mobile versions are generated too. |
--clear | Delete the stored Critical CSS of the site. When combined with --generate, the stored CSS is deleted first, everything is generated again, and the page cache is cleared at the end so pages use the new CSS. |
--network-wide | On multisite, apply --clear and --generate to every site in the network. |
Without an active license, the command stops with an error. --clear alone does not clear the page cache. See Critical CSS.
# Generate missing Critical CSS
wp powered-cache criticalcss --generate
# Regenerate everything for the whole network
wp powered-cache criticalcss --clear --generate --network-wide
ucss #
wp powered-cache ucss [--generate] [--clear] [--network-wide]
Works like criticalcss, for the used CSS of Remove Unused CSS: --generate creates missing used CSS, --clear deletes the stored used CSS, both together regenerate everything and then clear the page cache, and --network-wide covers every site. It also needs an active license.
wp powered-cache ucss --clear --generate
Multisite #
- purge: without
--post_id, it always clears the cache of the whole network. With--post_id, add--urlfor posts on another site than the main site. - preload, network-activated Powered Cache: one preload run covers every site of the network. Each site reads its own sitemaps. With
--network-wide, the network settings are used and--forceclears the page cache of every site before the run. Without it,--forceclears only the site given by--url. - preload, Powered Cache activated per site:
--network-widepreloads the sites one after another and prints Preloading for site: <id> for each. Without it, only the site given by--urlis preloaded. - criticalcss and ucss:
--network-wideprocesses every site. Without it, only the site given by--url.