Enforces WebP conversion best practices by requiring confirmation before image uploads
- ✅ Mandatory confirmation before uploading non-WebP images
- 🚫 Blocks upload if WebP conversion isn't confirmed
- 🖼️ Special SVG handling (bypasses confirmation)
- 🎨 Customizable modal dialog with WordPress styling
- 📱 Fully responsive design
- Download the plugin ZIP
- Go to WordPress Admin → Plugins → Add New → Upload
- Upload and activate
// Core functionality in webp-enforcer.php
add_filter('wp_handle_upload_prefilter', 'enforce_webp_format');
add_filter('upload_mimes', 'enable_svg_uploads');
function enforce_webp_format($file) {
$extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
$image_extensions = ['jpg', 'jpeg', 'png', 'gif'];
if (in_array($extension, $image_extensions)) {
$file['error'] = __('Please convert to WebP first', 'webp-enforcer');
}
return $file;
}- JPG/JPEG, PNG, GIF requires confirmation
- WebP, SVG/SVGZ don't require confirmation
Edit these variables in webp-enforcer.php
// Change modal text
const ALERT_MESSAGE = "Has this image been converted to WebP?";
const CONFIRM_TEXT = "Yes, proceed with upload";
const CANCEL_TEXT = "No, cancel upload";
git clone https://github.com/lazyZ33/webp-enforcer.git cd webp-enforcer
- Create a feature branch
- Make your changes
- Submit a pull request