Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save pirate-bot/4e3cf0241e82b0d7593900a883a1f924 to your computer and use it in GitHub Desktop.

Select an option

Save pirate-bot/4e3cf0241e82b0d7593900a883a1f924 to your computer and use it in GitHub Desktop.
Force fill resize to all images with exclusion rules
<?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