Filter hook 'img_caption_shortcode_width'

in WP Core File wp-includes/media.php at line 2592

View Source

img_caption_shortcode_width

Filter Hook
Description
Filters the width of an image's caption. 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.

Hook Information

File Location wp-includes/media.php View on GitHub
Hook Type Filter
Line Number 2592

Hook Parameters

Type Name Description
int $width Width of the caption in pixels. To remove this inline style, return zero.
array $atts Attributes of the caption shortcode.
string $content The image element, possibly wrapped in a hyperlink.

Usage Examples

Basic Usage
<?php
// Hook into img_caption_shortcode_width
add_filter('img_caption_shortcode_width', 'my_custom_filter', 10, 3);

function my_custom_filter($width, $atts, $content) {
    // Your custom filtering logic here
    return $width;
}

Source Code Context

wp-includes/media.php:2592 - How this hook is used in WordPress core
<?php
2587  	 * @param int    $width    Width of the caption in pixels. To remove this inline style,
2588  	 *                         return zero.
2589  	 * @param array  $atts     Attributes of the caption shortcode.
2590  	 * @param string $content  The image element, possibly wrapped in a hyperlink.
2591  	 */
2592  	$caption_width = apply_filters( 'img_caption_shortcode_width', $width, $atts, $content );
2593  
2594  	$style = '';
2595  
2596  	if ( $caption_width ) {
2597  		$style = 'style="width: ' . (int) $caption_width . 'px" ';

PHP Documentation

<?php
/**
	 * Filters the width of an image's caption.
	 *
	 * 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.
	 *
	 * @since 3.7.0
	 *
	 * @see img_caption_shortcode()
	 *
	 * @param int    $width    Width of the caption in pixels. To remove this inline style,
	 *                         return zero.
	 * @param array  $atts     Attributes of the caption shortcode.
	 * @param string $content  The image element, possibly wrapped in a hyperlink.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/media.php
Related Hooks

Related hooks will be displayed here in future updates.