Was just wondering how one could load a custom srcset stack. I know the srcset loads all registered sizes so I'm good on that side but I cannot find a way to remove the original src from there without string manipulation (ie. nuke all things until first comma) a la

$image_id = $image['ID'];
$img_srcset = wp_get_attachment_image_srcset( $image_id, '2560x' );
data-srcset="<?php echo substr(strstr($img_srcset, ', '), 2); ?>" 

I'm using lazysizes with a low quality placeholder so the src element uses a tiny 180x image. This let's me not disrupt the dom as much and loads everything to scale regardless of image ratios.

I also don't understand what order the srcset is made with. Currently it loads [original, 360x, 180x, 720x, 1280x] in my configuration.

Wordpress by default puts the original src image(addresses ios8 bug) which I don't want to use at all because my originals are nigh uncompressed 4K for wordpress to wrangle better resized derivatives from with imagemagick on the server. Even if most browser are smart enough to not load that first image, some are not and so google pagespeed still shakes its finger at you.

much love

*if anybody uses that string manipulation, One potential problem is that wordpress will not regenerate an intermediate size if your largest declaration is bigger than the source. So if you were to have 1280 and 2560 steps and upload a 1920px image, it would serve 1280 with the original removed from there. You can of course keep the string and attach it to the back end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.