How to use WP CLI for Imagify
You can optimize, generate WebP images, and restore backups directly from the command line using WP-CLI.
1. Bulk Optimize Images
To optimize your images in bulk, run the following command:
wp imagify bulk-optimize <contexts> [--lossless]
Context Options:
wp– Optimizes images in the Media Library.custom-folders– Optimizes images in your custom folders.- Note: You can pass one context or both separated by a space.
Optional Flag:
--lossless– Use this flag if you want lossless image compression (without quality loss).
2. Generate Missing WebP Images
To generate missing WebP files for your images, use:
wp imagify generate-missing-webp <contexts>
(Replace <contexts> with wp, custom-folders, or both.)
3. Restore Original Images
To restore your optimized images back to their unoptimized original versions from backups, use the restore command:
wp imagify restore [contexts]
Usage Examples:
wp imagify restore– Restores everything (both Media Library and custom folders).wp imagify restore library– Restores Media Library images only.wp imagify restore custom-folders– Restores custom folders only.wp imagify restore library custom-folders– Explicitly restores both Media Library and custom folders.
Important Notes:
- Images can only be restored if the “Backup original images” setting was enabled when they were optimized.
- The CLI output will display the number of successfully restored images alongside any errors (e.g.,
library: 12 restored, 0 errors out of 12 total). - Entering an invalid context will display an error message with the valid context list (
library,custom-folders).
Need Help on Command Line?
You can view full command instructions and options directly in your terminal at any time by running:
wp help imagify bulk-optimizewp help imagify generate-missing-webpwp help imagify restore
Your feedback has been sent to our team We value every bit of feedback we receive as it helps us to improve our products and services. Thank you for your time.