WordPress remove srcset-sizes conditionally

I have a problem that when i use: <?php echo wp_get_attachment_image( $image, $sizeImage ); ?> The page loading is sometimes to heavy cause the browsers load all the big images what should not happen. So i remove the biggest scrset attributes that are not needed: add_filter( 'wp_calculate_image_srcset', 'wzs_image_scrset', 10, 5); function wzs_image_scrset($sources, $size_array, $image_src, $image_meta, $attachment_id) { $remove = ['1536', '2048']; $sources = array_diff_key($sources, array_flip($remove)); return $sources; } But in some cases i need these big sizes. So is it possible to decide when i need the big images in wp_get_attachment_image and when not?

Comment (0)

You’ll be in good company