Title: img_caption_shortcode
Published: April 25, 2014
Last modified: February 24, 2026

---

# apply_filters( ‘img_caption_shortcode’, string $output, array $attr, string $content )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#wp--skip-link--target)

Filters the default caption shortcode output.

## 󠀁[Description](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#description)󠁿

If the filtered output isn’t empty, it will be used instead of generating the default
caption template.

### 󠀁[See also](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#see-also)󠁿

 * [img_caption_shortcode()](https://developer.wordpress.org/reference/functions/img_caption_shortcode/)

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#parameters)󠁿

 `$output`string

The caption output. Default empty.

`$attr`array

Attributes of the caption shortcode.

`$content`string

The image element, possibly wrapped in a hyperlink.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#source)󠁿

    ```php
    $output = apply_filters( 'img_caption_shortcode', '', $attr, $content );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/media.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/media.php#L2552)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/media.php#L2552-L2552)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#related)󠁿

| Used by | Description | 
| [img_caption_shortcode()](https://developer.wordpress.org/reference/functions/img_caption_shortcode/)`wp-includes/media.php` |

Builds the Caption shortcode output.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.6.0](https://developer.wordpress.org/reference/since/2.6.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/?output_format=md#comment-content-4732)
 2.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/img_caption_shortcode/#comment-4732)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fimg_caption_shortcode%2F%23comment-4732)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fimg_caption_shortcode%2F%23comment-4732)
 4. Example migrated from Codex:
 5.     ```php
        add_filter( 'img_caption_shortcode', 'my_img_caption_shortcode', 10, 3 );
    
        function my_img_caption_shortcode( $output, $attr, $content ) {
        	$attr = shortcode_atts( array(
        		'id'      => '',
        		'align'   => 'alignnone',
        		'width'   => '',
        		'caption' => ''
        	), $attr );
    
        	if ( 1 > (int) $attr['width'] || empty( $attr['caption'] ) ) {
        		return '';
        	}
    
        	if ( $attr['id'] ) {
        		$attr['id'] = 'id="' . esc_attr( $attr['id'] ) . '" ';
        	}
    
        	return '<div ' . $attr['id']
        	. 'class="wp-caption ' . esc_attr( $attr['align'] ) . '" '
        	. 'style="max-width: ' . ( 10 + (int) $attr['width'] ) . 'px;">'
        	. do_shortcode( $content )
        	. '<p class="wp-caption-text">' . $attr['caption'] . '</p>'
        	. '</div>';
    
        }
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fimg_caption_shortcode%2F%3Freplytocom%3D4732%23feedback-editor-4732)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fimg_caption_shortcode%2F)
before being able to contribute a note or feedback.