Created
December 1, 2020 10:31
-
-
Save xlawok/58fd7e0014eff840960fb622dd523d3a to your computer and use it in GitHub Desktop.
WP change srcset sizes max-width for archive thumbnails images
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
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