Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. /**
  2.  * Add custom image sizes attribute to enhance responsive image functionality
  3.  * for content images
  4.  *
  5.  * @since Twenty Sixteen 1.0
  6.  *
  7.  * @param string $sizes A source size value for use in a 'sizes' attribute.
  8.  * @param array  $size  Image size. Accepts an array of width and height
  9.  *                      values in pixels (in that order).
  10.  * @return string A source size value for use in a content image 'sizes' attribute.
  11.  */
  12. function mvi_content_image_sizes_attr( $sizes, $size ) {
  13.     $width = $size[0];
  14.  
  15.     1500 <= $width && $sizes = '(max-width: 768px) 92vw, (max-width: 992px) 700px, (max-width: 1199px) 930px, (min-width: 1200px) 1024px, $width';
  16.     1500 > $width && $sizes = '(max-width: 754px) 92vw, (min-width: 755px) 697px, $width';
  17.  
  18.     return $sizes;
  19. }
  20. add_filter( 'wp_calculate_image_sizes', 'mvi_content_image_sizes_attr', 10 , 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement