Skip to content

Instantly share code, notes, and snippets.

@vincentorback
Last active December 29, 2022 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vincentorback/7d15e461a01a3b5de3abd6306fe99933 to your computer and use it in GitHub Desktop.
Save vincentorback/7d15e461a01a3b5de3abd6306fe99933 to your computer and use it in GitHub Desktop.
Limit wordpress image sizes based on save data header
<?php
/**
* Limit image srcset width
* @link https://developer.wordpress.org/reference/hooks/max_srcset_image_width/
*/
function limit_image_srcset_width( $max_width = 2048, $size_array = [] ) {
$saveData = (isset($_SERVER["HTTP_SAVE_DATA"]) && stristr($_SERVER["HTTP_SAVE_DATA"], "on") !== false) ? true : false;
return $saveData ? 652 : $max_width;
}
add_filter( 'max_srcset_image_width', 'limit_image_srcset_width' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment