Created
February 26, 2026 08:15
-
-
Save pirate-bot/4e3cf0241e82b0d7593900a883a1f924 to your computer and use it in GitHub Desktop.
Force fill resize to all images with exclusion rules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| Plugin Name: Optimole Tweak - Force resize fill to most images | |
| Description: Force fill resize type to most images with smart cropping, excluding specific ones. | |
| Version: 0.0.1 | |
| */ | |
| add_filter('optml_image_args', function($args, $original_url) { | |
| // List of image URLs (or parts of them) to exclude | |
| $excluded_images = [ | |
| 'image-to-exclude-1.jpg', | |
| 'image-to-exclude-2.png', | |
| 'example-folder/excluded-image.jpg' | |
| ]; | |
| // Check if the original URL contains any excluded patterns | |
| foreach ($excluded_images as $exclude) { | |
| if (strpos($original_url, $exclude) !== false) { | |
| return $args; | |
| } | |
| } | |
| // Apply the 'fill' resize type to all other images | |
| $args['resize']['type'] = 'fill'; | |
| $args['resize']['gravity'] = 'sm'; | |
| return $args; | |
| }, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment