Optimizing images is crucial for website performance, and compressing images while you have to be actively using your website can be an inconvenient matter.
Luckily, there’s a solution that can streamline this process – WP-CLI, the great little gem WordPress has hidden from you. In this blog post, we’ll explore the power of WP-CLI and show you how to use it to optimize images with ease.
What is WP-CLI?
WP-CLI is the command line interface for WordPress, that allows users to manage their WordPress website, themes and plugins from the terminal, for example to install and manage plugins, update core files, create custom commands and much more. This means that if you want to use WP-CLI, you need to have some basic knowledge of how to use a terminal.
WP-CLI provides several commands that allow you to manage a WordPress website without having to log into the dashboard and navigate through the pages. Moreover, it is possible to use WP-CLI in scripts and even install WordPress itself on a server. In other words, WP-CLI was developed by the WordPress team, but it is not part of WordPress.
How can I use WP-CLI?
WP-CLI is not included in WordPress by default and needs to be installed on the hosting server, usually by your hosting provider. So the first thing you should do is contact them and ask for it. On the other hand, if you are the one who manages the server, please read this Quick Start Guide and see the installation and overall documentation of this tool.
Once it’s installed, just log in to your server and start typing! For example, the
wp plugin update --all command will update all plugins that have updates.
Take a look at all the currently available WP-CLI commands you can use: WP-CLI Commands | WordPress Developer Resources
Extending WP-CLI support with plugins
The best thing about WP-CLI is that plugins can also add support for WP-CLI. This also allows you to manage the functionality of your plugins, if the developers allow it. This means that you can, for example, optimize your images from the command line if your favorite image optimizer supports WP-CLI. And since we said that you can create scripts using the commands from WP-CLI, this means that you can easily create scripts to optimize images in the background.
For example, you could create a script to optimize all your images and add it as a cron job that runs in the background every hour without having to leave a tab of your WordPress admin open.
ShortPixel ❤️ WP-CLI
Yes, ShortPixel Image Optimizer supports WP-CLI! You can optimize all your images and check the optimization status easily with a few commands.
We leave you here the instructions you need to use ShortPixel to optimize your images: WP-CLI support for ShortPixel Image Optimizer