Support » Fixing WordPress » caption shortcode is not adding the style and width

  • Resolved lelandmcf


    I am developing a site and when I add an image with a caption, the width of the caption does not get transferred to the div that is created for the caption.
    [caption id="attachment_192" align="alignleft" width="147" caption="Caption Text"]<img class="size-thumbnail wp-image-192" title="Image Name" src="; alt="name" width="147" height="150" />[/caption]

    <div class="wp-caption alignleft" id="attachment_192"><img height="150" width="147" alt="Image Name" src="; title="Image Name" class="size-thumbnail wp-image-192"><p class="wp-caption-text">Caption Text</p></div>
    Note the missing style="width:147px;" in the wp-caption div. Any help would be appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • esmi


    Forum Moderator

    Have you tried:

    – deactivating all plugins to see if this resolves the problem? If this works, re-activate the plugins one by one until you find the problematic plugin(s).

    – switching to the default theme to rule out any theme-related problems?

    I’ve known plugins interfere with caption shortcode parsing.

    Ok, I figured it out. WordPress did not place a “;” after the css and the browser disregarded it all I did was added this PHP code to functions.php:

    function fb_img_caption_shortcode($attr, $content = null) {
    	// Allow plugins/themes to override the default caption template.
    	$output = apply_filters('img_caption_shortcode', '', $attr, $content);
    	if ( $output != '' )
    		return $output;
    		'id'	=> '',
    		'align'	=> 'alignnone',
    		'width'	=> '',
    		'caption' => ''
    	), $attr));
    	if ( 1 > (int) $width || empty($caption) )
    		return $content;
    	if ( $id ) $id = 'id="' . $id . '" ';
    	return '<div ' . $id . 'class="caption wp-caption ' . $align . '" style="width: ' . (10 + (int) $width) . 'px;">'
    	. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
    add_shortcode('wp_caption', 'fb_img_caption_shortcode');
    add_shortcode('caption', 'fb_img_caption_shortcode');

    Esmi –

    Your suggestion to deactivate all the plug-ins to see if that resolved the problem worked for me. I was able to narrow down the trouble to a faulty plug-in. Once removed, my captions came back.

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘caption shortcode is not adding the style and width’ is closed to new replies.