wp_calculate_image_srcset
Filters an image's 'srcset' sources.
Использование
add_filter( 'wp_calculate_image_srcset', 'wp_kama_calculate_image_srcset_filter', 10, 5 ); /** * Function for `wp_calculate_image_srcset` filter-hook. * * @param array $sources One or more arrays of source data to include in the 'srcset'. * @param array $size_array An array of requested width and height values. * @param string $image_src The 'src' of the image. * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'. * @param int $attachment_id Image attachment ID or 0. * * @return array */ function wp_kama_calculate_image_srcset_filter( $sources, $size_array, $image_src, $image_meta, $attachment_id ){ // filter... return $sources; }
- $sources(массив)
One or more arrays of source data to include in the 'srcset'.
-
width(массив)
-
url(строка)
The URL of an image source. -
descriptor(строка)
The descriptor type used in the image candidate string, either 'w' or 'x'. - value(int)
The source width if paired with a 'w' descriptor, or a pixel density value if paired with an 'x' descriptor.
-
-
- $size_array(массив)
An array of requested width and height values.
-
0(int)
The width in pixels. - 1(int)
The height in pixels.
-
- $image_src(строка)
- The 'src' of the image.
- $image_meta(массив)
- The image meta data as returned by 'wp_get_attachment_metadata()'.
- $attachment_id(int)
- Image attachment ID or 0.
Список изменений
С версии 4.4.0 | Введена. |
Где вызывается хук
wp-includes/media.php 1506
$sources = apply_filters( 'wp_calculate_image_srcset', $sources, $size_array, $image_src, $image_meta, $attachment_id );