钩子文档

wp_image_src_get_dimensions

💡 云策文档标注

概述

本文档介绍了 WordPress 中的 'wp_image_src_get_dimensions' 过滤器,用于修改图像源文件的宽度和高度维度。该过滤器允许开发者在获取图像尺寸时自定义或调整返回的维度数据。

关键要点

  • 'wp_image_src_get_dimensions' 是一个过滤器,用于过滤图像源文件的维度值。
  • 参数包括 $dimensions(数组或 false)、$image_src(图像源文件路径)、$image_meta(图像元数据)和 $attachment_id(附件 ID)。
  • 过滤器在 wp_image_src_get_dimensions() 函数中被调用,用于确定图像的宽度和高度。
  • 该过滤器从 WordPress 5.7.0 版本开始引入。

代码示例

apply_filters( 'wp_image_src_get_dimensions', $dimensions, $image_src, $image_meta, $attachment_id );

📄 原文内容

Filters the ‘wp_image_src_get_dimensions’ value.

Parameters

$dimensionsarray|false
Array with first element being the width and second element being the height, or false if dimensions could not be determined.
$image_srcstring
The image source file.
$image_metaarray
The image meta data as returned by ‘wp_get_attachment_metadata() ‘.
$attachment_idint
The image attachment ID. Default 0.

Source

return apply_filters( 'wp_image_src_get_dimensions', $dimensions, $image_src, $image_meta, $attachment_id );

Changelog

Version Description
5.7.0 Introduced.