wp_get_attachment_image_src
云策文档标注
概述
本文档介绍 WordPress 中的 wp_get_attachment_image_src 过滤器,用于修改附件图像源数据。该过滤器允许开发者在获取附件图像源时自定义返回的数组内容。
关键要点
- 过滤器名称:wp_get_attachment_image_src,用于过滤附件图像源结果。
- 参数:$image(图像数据数组或 false)、$attachment_id(附件 ID)、$size(图像尺寸)、$icon(是否作为图标处理)。
- 返回:应用过滤器后的 $image 数组,包含 URL、宽度、高度和是否调整大小的信息。
- 相关函数:wp_get_attachment_image_src() 用于检索附件图像。
- 版本历史:自 WordPress 4.3.0 引入。
原文内容
Filters the attachment image source result.
Parameters
$imagearray|false-
Array of image data, or boolean false if no image is available.
0stringImage source URL.1intImage width in pixels.2intImage height in pixels.3boolWhether the image is a resized image.
$attachment_idint-
Image attachment ID.
$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).
$iconbool-
Whether the image should be treated as an icon.
Source
return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Introduced. |