Can I optimize with WP-CLI?
2 min read · Last updated August 2026
Yes. SlashImage adds a wp slashimage command with five subcommands - status, optimize, restore, cancel, and migrate - so you can run and check optimization from the shell instead of the browser.
Why use the command line
The Bulk Optimize page is the easy choice for most sites. Reach for WP-CLI when the browser run is a poor fit:
- No request timeout.
wp slashimage optimizeruns in one long-lived process, so it is not bounded by the PHP-FPM or proxy request timeout that limits the browser bulk path. This is its main advantage for very large libraries. - No open tab. The run does not depend on a browser tab staying open.
- Works without WP-Cron. On hosts where WP-Cron is disabled, the command drives the work itself, so it runs where the background queue would otherwise stall.
- Migrates from a removed plugin.
wp slashimage migrateimports another optimizer's data even if that plugin has already been removed, which the Tools tab cannot do - it only lists optimizers that are still active. See How do I switch from ShortPixel or Imagify?.
Requirements
- WP-CLI installed and able to reach your site, usually over SSH to your host.
- SlashImage 1.1.0 or later, except
migrate, which needs 1.2.0 or later. Your installed version is shown on the Plugins page. - An API key for
optimize. Therestore,cancel, andmigratecommands work without one.
Settings come from the admin
There are no per-run flags for compression mode, WebP, AVIF, or backups. The commands read those from your saved settings. Change them at Media > SlashImage on the Settings tab first, then run the command.
See also
Was this helpful?