WordPress.org

Support

Support » How-To and Troubleshooting » Caption broken in new 3.4 posts

Caption broken in new 3.4 posts

Viewing 15 replies - 16 through 30 (of 42 total)
  • Hi. I tried the fix suggested above, and every time I toggled between the html tab and visual tab, WordPress changed the code back to the original code. Meaning that nothing changed. You can see an example of the funky caption thing going on–all flush right–here: http://www.phillyonthecheap.com/2012/06/25/flip-flops-for-a-buck/

    I would appreciate any suggestions. Thanks.

    Leah

    Hi leahingram,

    you are right, WordPress puts the caption back when you go back to the Visual Editor. The only way to make those changes permanent is to not change back to the Visual Editor until you’ve published your post.

    If you’re making edits after you’ve published, switching back to the Visual Editor will also change your captions back to the “broken” version. I suggest to make edits in HTML view. You can even switch the Visual Editor off altogether if you like under Users – Your Profile (check the first tickbox “Disable visual editor”).

    Hello everyone.

    This is a deliberate change in WordPress 3.4. Instead of having caption="" as an attribute of the [caption] shortcode, WordPress inserts the caption into the main content of the shortcode, after the image and in between [caption] and [/caption].

    This change in 3.4 was necessary to allow for HTML in captions. But, like everything we develop, it was deliberately coded so it would be backwards compatible. Any theme using the ‘img_caption_shortcode’ filter to override how a caption is generated would work swimmingly, even though the format changed.

    If I had to guess, the common issue for all for these themes is that they call add_shortcode( 'caption', 'some_function_in_their_theme' ); to customize the caption, instead of using the aforementioned filter. This is wrong. Themes should not be doing this. If the theme you are using does this, please contact the theme author. If they disagree it is a problem with their theme, I’d be happy to explain it to them.

    I came here after seeing a bug report, but note that after two weeks and 2.5 million downloads, this is the only thread I’ve seen on this issue, so thankfully it does not appear to be adversely affecting many sites. I’m sorry if it has affected you. If you do know of any other threads, please link them to me.

    Thanks,
    Nacin

    Thanks for letting us know Nacin, think we were getting worried there 😉 I understand the code change, makes sense to allow for HTML in captions.

    I’ve just tested the two latest versions of TwentyTen and TwetyEleven, they’re both looking good. Thesis have released a patch for this too.

    @caseylessard you best get in touch with the Headway guys and make them aware of this change in WordPress.

    Hi Nacin,

    Thanks for letting us know – I’ve done Jay’s manual fix on my image captions (one by one – very annoying):

    After WP 3.4:

    [caption id="attachment_762" align="aligncenter" width="300"]<a href="http://lexireidstudio.com/2012/06/17/shadow-boxes-and-three-dimensional-collages/assemblage-1-2/" rel="attachment wp-att-762"><img class="size-medium wp-image-762 " title="Waxed images and abstract encaustic paintings ready for collage assembly." src="http://lexireidstudio.com/wordpress/wp-content/uploads/2012/06/assemblage-13-300x230.jpg" alt="" width="300" height="230" /></a> Waxed images and abstract encaustic paintings ready for collage assembly.[/caption]

    Manual change: moving caption and fixing alignment

    [caption id="attachment_762" align="alignnone" width="300" caption=”Waxed images and abstract encaustic paintings ready for collage assembly.”]<a href="http://lexireidstudio.com/2012/06/17/shadow-boxes-and-three-dimensional-collages/assemblage-1-2/" rel="attachment wp-att-762"><img class="size-medium wp-image-762 " title="Waxed images and abstract encaustic paintings ready for collage assembly." src="http://lexireidstudio.com/wordpress/wp-content/uploads/2012/06/assemblage-13-300x230.jpg" alt="" width="300" height="230" /></a> Waxed images and abstract encaustic paintings ready for collage assembly.[/caption]

    Will I have to keep doing this for every image on every new post??

    @lexistudio: Your site is using Twenty Eleven, which means things should be fine. So most likely, you have a plugin interfering with your captions. I would work to figure out what plugin it is. You will likely be better served by opening your own support thread.

    The alternative is doing this for every image on every new post. But if you figure out what plugin it is, I’ll see to it that it gets fixed.

    Thanks Andrew – I did start another thread on this topic (there’s at least 4 others that I know of) – and I did inactivate my plugins (I only have 3 – jetpack,askimet, and subscribe to comments). Still is an issue for me.

    Thank you, Rosie-L & Jay Versluis, for a masterful solution to the caption problem!

    You were absolutely right: it was a WordPress code issue. Adding Caption= “” within the opening caption tag, & transposing the caption title (by cut-&-paste) within those quotes, fixed everything.

    You saved me hours of de-activating plug-ins & blindly shooting in the dark for a coding solution. Thanks again for putting the word out there for the rest of us.

    Moderator kmessinger

    @kmessinger

    If you are using Thesis, they have posted a temporary fix for their theme.

    I have a few themes that use the add_shortcode( 'caption' ) culprit mentioned by Nacin . It’s used to remove the inline width style that is added to caption’s for responsive CSS design purposes.

    Unfortunately, I don’t think there’s going to be anyway to achieve this without replacing the caption shortcode like this.

    I take that back, I was misunderstanding the value of the img_caption_shortcode filter, for my specific situation this worked nicely:

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    I had this same issue no matter what theme I chose – even Twenty Eleven and no plugins. Or so I thought.

    It turned out the display of the caption was just messed up in the editor, but when I previewed the page it looked fine.

    How can i fix the theme?
    How do i change the add_shortcode to img_caption_shortcode?

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. Don’t use blockquoute, code formats poorly that way. ]

    I have managed to fix it with the help of Function Reference/add filter.
    I replaced the add_shortcode('wp_caption', 'zack_img_caption_shortcode'); in the Zack990 theme functions.php with the
    ‘my_img_caption_shortcode_filter’
    in the link and modified some of the syntax to give the same output as the previous code.

    add_filter('img_caption_shortcode', 'my_img_caption_shortcode_filter',10,3);
    function my_img_caption_shortcode_filter($val, $attr, $content = null)
    {
    	extract(shortcode_atts(array(
    		'id'	=> '',
    		'align'	=> '',
    		'width'	=> '',
    		'caption' => ''
    	), $attr));
    
    	if ( 1 > (int) $width || empty($caption) )
    		return $val;
    
    	$capid = '';
    	if ( $id ) {
    		$id = esc_attr($id);
    		$capid = 'id="figcaption_'. $id . '" ';
    		$id = 'id="' . $id . '" aria-labelledby="figcaption_' . $id . '" ';
    	}
    
    	return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: '
    	. (4 + (int) $width) . 'px">' . do_shortcode( $content ) . '<p ' . $capid
    	. 'class="wp-caption-text">' . $caption . '</p></div>';
    }

    Check whether there is any update for your theme after WP 3.4 release. Most of the themes have solved this issue through minor update.

Viewing 15 replies - 16 through 30 (of 42 total)
  • The topic ‘Caption broken in new 3.4 posts’ is closed to new replies.
Skip to toolbar