Thread Starter
ze3kr
(@ze3kr)
There definitely some thing break the srcset function, as I disabled this plugin, the srcset is correct. I am going to have a deep look in it.
Thread Starter
ze3kr
(@ze3kr)
I have found this bug, it is because the max_srcset_image_width is return 1 when this plugin is enabled. It returns 1600 when this plugin is disabled. I tried remove it and it works!
function remove_max_srcset_image_width( $max_width ) {
return false;
}
add_filter( 'max_srcset_image_width', 'remove_max_srcset_image_width', 99 );
Hello,
Thank you for pointing this out, will pass it to the development team.
Thx for this trick, @ze3kr.
I also noticed that the srcset images were loaded from the local uploads-folder instead of the google bucket.
I created a quick fix (for my multisite setup, hence the $blog_id):
function stateless_cdn_srcset($sources){
if (is_plugin_active( 'wp-stateless/wp-stateless-media.php' )) {
foreach ( $sources as $source ) {
$sources[ $source['value'] ][ 'url' ] = str_replace($uploads, 'https://storage.googleapis.com/'. $bucket . '/' . $blog_id . '/', $sources[ $source['value'] ][ 'url' ]);
}
}
return $sources;
}
add_filter( 'wp_calculate_image_srcset', 'stateless_cdn_srcset');
Cheers!
Thanks for the help @emiliopro!
I’ve created an issue for this on github to track official support for srcset within WP-Stateless at https://github.com/wpCloud/wp-stateless/issues/18
Feel free to follow along and add comments. Thanks!