• 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

    (@johned78)

    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.