Prerequisites
Before running any optimization commands, ensure your environment meets the following requirements:
- 1. WP-CLI Installed
Your server should have the WordPress Command Line Interface (WP-CLI) installed and properly configured to interact with your WordPress installation. - 2. SSH Access
Or you should have valid SSH credentials and be able to connect to your server environment via a terminal application (e.g., Terminal, PuTTY, or iTerm2). - 3. Active License
WP-CLI support is a premium feature exclusive to CompressX Pro. Before executing commands, ensure that your Pro license is active and the plugin is validated on the site.
How to Use CompressX via WP-CLI
Follow these steps to manage and automate your image optimization directly from the command line.
1. Connect and Navigate to Your Site
Log in to your website server via SSH and navigate to your WordPress root directory (where wp-config.php is located):
cd /var/www/html/yourdomain.com/public_html2. Scan for Unconverted Images
Use the scan command below to analyze your Media Library to identify original images that do not yet have corresponding WebP or AVIF versions. This is a recommended first step to understand the scope of work:
wp compressx scan3. Convert Images to WebP/AVIF
Trigger the optimization process for all images in your WordPress media library or target a specific file.
- Bulk Conversion
Processes all eligible images in the WordPress Media Library based on your optimization settings:
wp compressx convert- Single Image Conversion
Optimizes a specific asset by targeting its unique attachment ID:
wp compressx convert --type single --image=IDTo find an Image ID, you can go to your WordPress Media Library (List View), hover over the image title. The ID is the number found after post= in the URL displayed at the bottom of your browser (e.g., …post=123… means the ID is 123).
4. Delete Converted Images
Use the delete command below to remove generated WebP/AVIF images if you need to free up disk space or reset your optimization status:
- Bulk Delete
To delete all WebP and AVIF images and database records generated by CompressX from your server:
wp compressx delete- Single Delete
To delete converted WebP and AVIF images and database records for a specific image:
wp compressx delete --type single --image=IDThe delete command only removes the generated WebP and AVIF files. Your original JPG or PNG source files remain untouched.


