{"id":982,"date":"2024-02-21T14:44:55","date_gmt":"2024-02-21T14:44:55","guid":{"rendered":"https:\/\/imagify.io\/documentation\/?p=982"},"modified":"2026-07-23T07:38:50","modified_gmt":"2026-07-23T07:38:50","slug":"how-to-use-wp-cli-for-imagify","status":"publish","type":"post","link":"https:\/\/imagify.io\/documentation\/how-to-use-wp-cli-for-imagify\/","title":{"rendered":"How to use WP CLI for Imagify"},"content":{"rendered":"\n<p>You can optimize, generate WebP images, and restore backups directly from the command line using WP-CLI.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Bulk Optimize Images<\/h3>\n\n\n\n<p>To optimize your images in bulk, run the following command:<\/p>\n\n\n\n<p><code>wp imagify bulk-optimize &lt;contexts&gt; [--lossless]<\/code><\/p>\n\n\n\n<p><strong>Context Options:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>wp<\/code> \u2013 Optimizes images in the Media Library.<\/li>\n\n\n\n<li><code>custom-folders<\/code> \u2013 Optimizes images in your custom folders.<\/li>\n\n\n\n<li><em>Note: You can pass one context or both separated by a space.<\/em><\/li>\n<\/ul>\n\n\n\n<p><strong>Optional Flag:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>--lossless<\/code> \u2013 Use this flag if you want lossless image compression (without quality loss).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. Generate Missing WebP Images<\/h3>\n\n\n\n<p>To generate missing WebP files for your images, use:<\/p>\n\n\n\n<p><code>wp imagify generate-missing-webp &lt;contexts&gt;<\/code><\/p>\n\n\n\n<p><em>(Replace <code>&lt;contexts&gt;<\/code> with <code>wp<\/code>, <code>custom-folders<\/code>, or both.)<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Restore Original Images<\/h3>\n\n\n\n<p>To restore your optimized images back to their unoptimized original versions from backups, use the restore command:<\/p>\n\n\n\n<p><code>wp imagify restore [contexts]<\/code><\/p>\n\n\n\n<p><strong>Usage Examples:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>wp imagify restore<\/code> \u2013 Restores everything (both Media Library and custom folders).<\/li>\n\n\n\n<li><code>wp imagify restore library<\/code> \u2013 Restores Media Library images only.<\/li>\n\n\n\n<li><code>wp imagify restore custom-folders<\/code> \u2013 Restores custom folders only.<\/li>\n\n\n\n<li><code>wp imagify restore library custom-folders<\/code> \u2013 Explicitly restores both Media Library and custom folders.<\/li>\n<\/ul>\n\n\n\n<p><strong>Important Notes:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Images can only be restored if the <em>&#8220;Backup original images&#8221;<\/em> setting was enabled when they were optimized.<\/li>\n\n\n\n<li>The CLI output will display the number of successfully restored images alongside any errors (e.g., <code>library: 12 restored, 0 errors out of 12 total<\/code>).<\/li>\n\n\n\n<li>Entering an invalid context will display an error message with the valid context list (<code>library<\/code>, <code>custom-folders<\/code>).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Need Help on Command Line?<\/h3>\n\n\n\n<p>You can view full command instructions and options directly in your terminal at any time by running:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>wp help imagify bulk-optimize<\/code><\/li>\n\n\n\n<li><code>wp help imagify generate-missing-webp<\/code><\/li>\n\n\n\n<li><code>wp help imagify restore<\/code><\/li>\n<\/ul>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>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 &lt;contexts&gt; [&#8211;lossless] Context Options: Optional Flag: 2. Generate Missing WebP Images To generate missing WebP files for your images, use: wp imagify [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-982","post","type-post","status-publish","format-standard","hentry","category-image-optimization"],"_links":{"self":[{"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/posts\/982","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/comments?post=982"}],"version-history":[{"count":8,"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/posts\/982\/revisions"}],"predecessor-version":[{"id":1272,"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/posts\/982\/revisions\/1272"}],"wp:attachment":[{"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/media?parent=982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/categories?post=982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/tags?post=982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}