Skip to content

Instantly share code, notes, and snippets.

@xlawok
Created December 1, 2020 10:31
Show Gist options
  • Save xlawok/58fd7e0014eff840960fb622dd523d3a to your computer and use it in GitHub Desktop.
Save xlawok/58fd7e0014eff840960fb622dd523d3a to your computer and use it in GitHub Desktop.
WP change srcset sizes max-width for archive thumbnails images
add_filter( 'wp_calculate_image_sizes', 'pk_content_archive_thumbnail_image_sizes', 10, 5 );
/**
* Change the default "sizes" attribute created by WordPress
* for the content archive thumbnails
*/
function pk_content_archive_thumbnail_image_sizes( $sizes, $size, $image_src, $image_meta, $attachment_id ) {
if( is_archive() && is_main_query() || is_home() ) {
$sizes = '(max-width: 600px) 100vw, 50vw';
}
return $sizes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment