auto click the smush button in wordpress

The free version of Smush provides you an easy way to compress your images automatically without having to individually do it yourself. However, with the free version, Smush only compresses 50 images per click, which means it can be annoying to optimize your images if you have over 300 of them. Thankfully, there is a simple jQuery/JavaScript script solution to help you with automation so you don’t have to be at the computer for every 50 images that need optimizing.

How to run the script

This is the script that will automatically press the button for you.

setInterval(function(){ 
	botao = jQuery('.wp-smush-all.sui-button.sui-button-blue');
	if( botao.attr('disabled') != 'disabled' ) {
		botao.trigger('click');
	}
}, 1000);
  1. Copy the code above
  2. Go to the dashboard page of the Smush plugin where the button is
  3. Open the browsers Inspect Element tool by clicking F12 or by Right Click > Inspect (On Chrome)
  4. Go to the Console tab
  5. Paste the code and press Enter. Your done!
script for auto click smush plugin

After you ran the code it should work already be automatically clicking the button for you.

The process may differ from browser to browser. To make it easier to follow you can use the Google Chrome browser as I have in the screenshots.

If the script happens to not work, use the selection tool in Inspect element and click on the blue bulk smush button to find an updated selector that targets the button and replace it in the code on the second line.

Lastly, if you’re interested I made a step by step guide on how to increase your website speed without using plugins to make your website even faster.

Leave a Reply