Title: Change caption output
Last modified: August 22, 2016

---

# Change caption output

 *  [johned78](https://wordpress.org/support/users/johned78/)
 * (@johned78)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/change-caption-output/)
 * Hi,
 * Im currently using the image caption shortcode and the text is outputted in a
   <p> tag. Is there and hook or function I can use to change from a p tag to a 
   div?
 * The reason is I want to add html that would not work inside a p such as h2 etc.
 * Thanks.

Viewing 1 replies (of 1 total)

 *  Thread Starter [johned78](https://wordpress.org/support/users/johned78/)
 * (@johned78)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/change-caption-output/#post-5522280)
 * And to answer my own question 🙂 in case anyone else is trying to figure this
   out..
 *     ```
       add_filter('img_caption_shortcode', 'gn_caption_shortcode_filter',10,3);
       function gn_caption_shortcode_filter($val, $attr, $content = null)
       {
       	extract(shortcode_atts(array(
       		'id'	=> '',
       		'align'	=> 'alignnone',
       		'width'	=> '',
       		'caption' => ''
       	), $attr));
   
       	if ( 1 > (int) $width || empty($caption) )
       		return $val;
   
       	if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
   
       	return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (int) $width . 'px">'
       	. do_shortcode( $content ) . '<div class="wp-caption-text">' . $caption . '</div></div>';
       }
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Change caption output’ is closed to new replies.

## Tags

 * [caption shortcode](https://wordpress.org/support/topic-tag/caption-shortcode/)

 * 1 reply
 * 1 participant
 * Last reply from: [johned78](https://wordpress.org/support/users/johned78/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/change-caption-output/#post-5522280)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
