Compress Only PNG images With TinyPNG WordPress Plugin

This modifies the Compress JPEG & PNG images plugin for WordPress (the one by TinyPNG).

This will let you use your 500 free compressions per month more profitably since JPEG images will not be compressed. After making this change, only PNG images will be compressed, not JPEG images.

Because WordPress already compresses JPEG. So, why should this plugin compress them again, and count them against your 500 free monthly compressions?

This quick change will make the plugin ignore JPEG images so they won’t be compressed or counted against your 500 free compressions for the month.

If you also pay for more compressions from the TinyPNG service, you will save money with this by paying only for PNG images, not JPEG.

This modifies a core file of the plugin, and this is not recommended unless you are maintaining a fork of the plugin and you know what you’re doing. The plugin currently offers no hook or filter to do this any other way, as of version 3.2.1.

Change Just 1 Line

  1. Find the file named “class-tiny-image.php” in the plugin folder:


  2. Change line 167 from this:
    return in_array( $this->get_mime_type(), array( 'image/jpeg', 'image/png' ) );

    …to this:

    return ( 'image/png' === $this->get_mime_type() );

    Note: If you couldn’t find that specific code at line 167, look for the file_type_allowed() function in the plugin because the line will be inside that function.

See more:

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this: