Last active
December 29, 2022 14:44
-
-
Save vincentorback/7d15e461a01a3b5de3abd6306fe99933 to your computer and use it in GitHub Desktop.
Limit wordpress image sizes based on save data header
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 | |
/** | |
* 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