wp_calculate_image_sizes
云策文档标注
概述
wp_calculate_image_sizes 是一个 WordPress 过滤器,用于修改 wp_calculate_image_sizes() 函数输出的 'sizes' 属性值。它允许开发者根据图像尺寸、元数据等参数自定义响应式图像的大小描述。
关键要点
- 这是一个过滤器钩子,用于调整图像 'sizes' 属性的生成逻辑。
- 接受多个参数,包括图像尺寸、URL、元数据和附件 ID,提供灵活的定制选项。
- 自 WordPress 4.4.0 版本引入,是处理响应式图像的重要工具。
代码示例
apply_filters( 'wp_calculate_image_sizes', $sizes, $size, $image_src, $image_meta, $attachment_id );
原文内容
Filters the output of ‘wp_calculate_image_sizes() ’.
Parameters
$sizesstring-
A source size value for use in a
'sizes'attribute. $sizestring|int[]-
Requested image size. Can be any registered image size name, or an array of width and height values in pixels (in that order).
$image_srcstring|null-
The URL to the image file or null.
$image_metaarray|null-
The image meta data as returned by wp_get_attachment_metadata() or null.
$attachment_idint-
Image attachment ID of the original image or 0.
Source
return apply_filters( 'wp_calculate_image_sizes', $sizes, $size, $image_src, $image_meta, $attachment_id );
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |