钩子文档

img_caption_shortcode_width

💡 云策文档标注

概述

img_caption_shortcode_width 是一个 WordPress 过滤器,用于控制图像标题的宽度。默认情况下,标题宽度比图像宽 10 像素,以防止内容与浮动图像冲突。

关键要点

  • 过滤器名称:img_caption_shortcode_width
  • 参数:$width(标题宽度,像素)、$atts(短代码属性数组)、$content(图像元素内容)
  • 默认行为:标题宽度为图像宽度加 10 像素
  • 用途:可自定义或移除标题的宽度样式,例如通过返回零来删除内联样式

代码示例

// 移除图像标题的额外宽度
add_filter( 'img_caption_shortcode_width', '__return_zero' );

注意事项

此过滤器自 WordPress 3.7.0 版本引入,与 img_caption_shortcode() 函数相关,用于构建标题短代码输出。


📄 原文内容

Filters the width of an image’s caption.

Description

By default, the caption is 10 pixels greater than the width of the image, to prevent post content from running up against a floated image.

See also

Parameters

$widthint
Width of the caption in pixels. To remove this inline style, return zero.
$attsarray
Attributes of the caption shortcode.
$contentstring
The image element, possibly wrapped in a hyperlink.

Source

$caption_width = apply_filters( 'img_caption_shortcode_width', $width, $atts, $content );

Changelog

Version Description
3.7.0 Introduced.

User Contributed Notes