WP-CLI 0

How to bulk optimise images on a WordPress Multisite Network using Smush


Optimising images is one of the most effective ways to improve your WordPress site's performance. When you're managing a WordPress Multisite Network, this process can be a bit more complex, as you'll need to optimize images across all sites within the network. Fortunately, the Smush plugin allows for bulk image optimization, and you can even optimise images from the command line using WP-CLI.

In this article, we'll walk you through how to bulk optimise images across a WordPress Multisite Network using Smush and WP-CLI.

Prerequisites

Before proceeding, make sure that:

  • You have Smush installed and activated on your WordPress Multisite Network.
  • You have WP-CLI installed and configured for your WordPress Multisite Network.
  • Your user role has appropriate permissions to execute WP-CLI commands across the network.

Step-by-Step Guide

  1. Install and Activate Smush on the Network

    First, ensure that the Smush plugin is installed on your network and activated on all sites. You can do this from the network admin dashboard.

  2. Navigate to the root of your WordPress installation.

    Once you have connected to your hosting account with via ssh or the built in terminal, you will need to navigate to the directory that WordPress is installed.

    On our cPanel hosting, this would be ~/public_html/ by default.

  3. Using WP-CLI to Bulk Optimise Images

    After connecting to your server via SSH or terminal and navigating to your WordPress root directory, you can use a command to bulk optimise images across all sites in your Multisite Network.

    The command is:

    • wp site list --field=url | xargs -n1 -I % wp --url=% smush compress

    Let's break it down:

    • wp site list --field=url: This command retrieves a list of all URLs for the sites in your WordPress Multisite Network.
    • xargs -n1 -I %: This command takes the list of URLs and runs the following Smush optimization command for each site. -n1 ensures each site's URL is processed one by one.
    • wp --url=% smush compress: This command uses WP-CLI to compress images for each site. The --url=% part tells WP-CLI to run the Smush plugin's compress command on each site individually.
  4. Monitoring the Process

    The command will begin processing each site in your network. Depending on the number of sites and the image files, this process may take some time.

    Smush will compress all images in each site's media library. It will automatically optimise images by stripping unnecessary metadata, resizing them, and applying other optimization techniques.

  5. Verifying the Results

    • Once the command finishes running, visit the front-end of each site to confirm that images have been optimised.
    • You can also check the Smush plugin settings to see the results of the compression, including the amount of space saved.

Tips for Effective Image Optimization

  • Backup Your Media: It's always a good idea to back up your images before performing bulk operations.
  • Adjust Smush Settings: If you're running into limits, you may need to adjust the Smush settings to ensure it's applying the best optimization options for your needs.
  • Use Lazy Loading: Smush also offers lazy loading for images, which can further improve site performance.

Conclusion

Using WP-CLI and Smush, you can quickly and efficiently bulk optimise images across your WordPress Multisite Network. The command provided allows you to optimise images on all sites without needing to log into each one individually, saving time and improving your network's overall performance.

If you need further assistance with WP-CLI or Smush, feel free to contact our support team!


Was this answer helpful?

One email a month. Endless business benefits.

Don't miss out on WMTWWFY — the newsletter that keeps your website fast, safe, and visible.

« Back
Spinner
aluminium-anthropoid Security Check