Rewrite image src
and srcset
URLs for optimized delivery of responsive sizes from services that support dynamic resizing such as Photon, Cloudflare Images and others.

The plugin uses additional widths (384, 768, 1024, 1536 and 2048) for each of the defined image sizes to ensure that wp_calculate_image_srcset
has plenty of sizes to use for each breakpoint width.
It is recommended to use image sizes add_image_size()
to define the available aspect ratios instead of the different sizes. This ensures that editors only need to choose the aspect ratio when adding images to content and the responsive sizes are generated automatically.
Importantly, the plugin doesn’t disable intermediate image generation wp_generate_attachment_metadata()
so may choose to disable that via the intermediate_image_sizes_advanced
filter:
add_filter( 'intermediate_image_sizes_advanced', '__return_empty_array' );
Usage
Use the image_pilot__image_url
filter to specify the updated image URL for the specific sizes:
add_filter(
'image_pilot__image_size_url',
function ( string $url, \WPElevator\Image_Pilot\Image_Size $target_size ) {
return $url; // Rewrite the original image URL to the resized URL.
},
);