[WP Smush Pro] Exclude PNG files from smushing

We are having an issue with PNG files becoming blurry after being smushed. We are creating graphics and charts as PNG files offline and uploading them. After smushing they get noticable blur to the text.

I looked through the settings in Smush Pro to see if there was some way to ignore file types, but there isn't. We still want to Smush JPGs to keep the site performing well, but we would like to exclude PNGs – is there any programmatic way to tell Smush to exclude PNG files from the process when they are uploaded?

  • Ash
    • Code Norris

    Hello Saunt Valerian

    Please try the following code:

    add_filter( 'wp_smush_image', function( $status, $id ) {
    return ! strpos( get_post_mime_type( $id ), 'png' );
    } );

    You can use this code in your child theme’s functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    About the blur issue, that should not happen. Would you please attach the original image and send us a link to the smushed image so that we can compare?

    Have a nice day!

    Cheers,

    Ash