Roots Discourse

Image captions broken by a p tag

sage8
#1

Hi,

I’ve got a strange issue with image captions. Adding an image within a paragraph where the text is wrapped around the image works OK. The issue is adding an image with a caption; a closing </p> tag is added right before the <figure, and as a result, the text wrapping and font size is broken. No <p> tag is added after the </figure> tag. There are orphaned </p> tags at the end of the paragraph.

This is using the classic editor and not Gutenberg. I’ve looked in theme functions in Sage Starter and don’t see anything that would impact WordPress autop, or strips <p> tags from images, etc.

Any ideas?

From Dev Tools:

<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </p><figure id="attachment_2239" aria-describedby="caption-attachment-2239" style="width: 300px" class="wp-caption alignleft"><img src="example.com/wp-content/uploads/2018/10/kitten-300x262.jpg" alt="image" width="300" height="262" class="size-medium wp-image-2239" /><figcaption id="caption-attachment-2239" class="wp-caption-text">A little kitten captionlaborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</p>
</p>

1 Like

#2

WordPress has dozens of bugs with wpautop that are ancient and will likely never be fixed. Have you tried this same markup on a different theme?

There’s nothing in Sage that would be responsible for this AFAIK

0 Likes

#3

Thanks, adding images with captions via the Media Library works fine in other themes. The above markup resulted in inserting from the Media Library in Sage, so something somewhere is adding that p tag. I did have to add the CSS for the WordPress standard alignleft, etc., image alignment to the site stylesheet, so text would wrap around images. That’s when I discovered captions were broken. This is a site I inherited; is it possible some theme functions weren’t originally compiled in the theme? I’m a beginner with Sage and composer, etc.

0 Likes

#4

It’s possible there might be something in the theme conflicting, but Sage out of the box would be fine

Is the Soil plugin activated on the site? If so, is it the latest version?

0 Likes

#5

That’s interesting; in setup.php, I see

add_theme_support(‘soil-clean-up’);
add_theme_support(‘soil-nav-walker’);
add_theme_support(‘soil-nice-search’);
add_theme_support(‘soil-jquery-cdn’);
add_theme_support(‘soil-relative-urls’);

But there is no Soil plugin active; so I commented out those lines and there is no difference in the site or in the captions.

0 Likes

#6

What version of WP are you on? Have you tried disabling all plugins?

https://core.trac.wordpress.org/ticket/39307

0 Likes

#7

Good point; I should have checked the Trac. Seems like that or a similar bug has reappeared in some cases, even with WP 5.2, twentynineteen and no plugins.

0 Likes

#8

This appears to be a new or old wpautop bug that has resurfaced when using the Classic Editor plugin.

0 Likes