📥 My Awesome Plugin
This plugin helps you automate tasks and improve web performance.
⬇️ Download Plugin ZIP💌 Subscribe to Updates
This WordPress free plugin “Media Optimizer” that automatically compresses images uploaded to the WordPress media library using the TinyPNG API. The plugin is designed for non-coders, with a simple settings page to enter the TinyPNG API key and enable/disable compression. It will compress JPEG and PNG images on upload, supporting all image sizes generated by WordPress. The plugin is lightweight, secure, and includes an admin page for configuration and instructions.
WordPress Media Optimizer free plugin
Installation and Setup Instructions
- Download the Plugin:
- Upload to WordPress:
- Zip the wp-media-optimizer folder.
- In your WordPress admin dashboard, go to Plugins > Add New > Upload Plugin.
- Upload the zipped folder and click Install Now.
- Activate the Plugin:
- After installation, click Activate Plugin.
- Configure TinyPNG API Key:
- Go to tinypng.com/developers and sign up for a free API key.
- In the WordPress admin dashboard, go to the new menu item called Image Compressor.
- Enter your TinyPNG API Key.
- Check Enable Compression (default: enabled).
- Click Save Changes.
- Upload Images:
- Upload images via the Media Library or page/post editor.
- The plugin automatically compresses JPEG and PNG images (including thumbnails and other sizes) using the TinyPNG API.
Features
- Automatic Compression: Compresses JPEG and PNG images on upload using the TinyPNG API.
- All Image Sizes: Applies compression to full-size images and all WordPress-generated sizes (e.g., thumbnail, medium, large).
- Configurable: Enable/disable compression and set API key via a settings page.
- Simple Interface: Easy-to-use settings page for non-coders.
- Admin Instructions: Includes guidance on the settings page.
- Single File: All functionality is contained in one PHP file.
- Secure: Uses WordPress best practices for API requests and data handling.
How It Works
- On plugin activation, it adds a settings page to configure the TinyPNG API key and compression settings.
- When an image is uploaded:
- The plugin checks if compression is enabled and if a valid API key is set.
- It sends the image to the TinyPNG API for compression.
- The compressed image replaces the original for all sizes.
- File sizes are updated in the attachment metadata.
- Compression is lossless for quality but significantly reduces file size, improving site performance.
Notes
- Requirements: Requires a TinyPNG API key and server support for outbound HTTPS requests (most hosts support this).
- Supported Formats: Compresses JPEG and PNG images only.
- Permanent Compression: Compressed images replace originals. Keep backups of original images if needed.
- API Limits: The free TinyPNG plan allows 500 compressions per month. Monitor usage via your TinyPNG account.
- Error Handling: Errors (e.g., invalid API key, API limits exceeded) are logged to the WordPress debug log (wp-content/debug.log) if debugging is enabled.
- Compatibility: Works with WordPress 5.0 and above.
- Performance: Compression occurs during upload, with minimal impact on server performance due to TinyPNG’s cloud processing.
Troubleshooting
- Images Not Compressing: Check your API key, ensure compression is enabled, and verify your server allows HTTPS requests to api.tinify.com.
- API Limit Reached: Upgrade to a paid TinyPNG plan or wait until the next month for free plan resets.
- Debugging: Enable WordPress debugging (define(‘WP_DEBUG’, true); in wp-config.php) to view error logs.
This plugin is ready to use and provides a simple way to optimize images for faster page loads. Let me know if you need additional features (e.g., bulk compression for existing images, compression level settings, or WebP conversion) or help with setup!