Gutenberg: Captions from image blocks included in excerpt
-
Hi, thank you for this nice plugin.
Unfortunately I’ve stumbled over a problem with the Gutenberg Editor. Our posts start with an image which sometimes has a caption. This caption text is then preceded before the actual content of the post in the excerpt. We don’t want the image caption in the excerpt. Also it looks ugly as no spaces added between the caption and the other content.
The caption text can be found in
<figcaption>
in the<!-- wp:image -->
block. I’m calling the template function with exclude_tags but the text enclosed by<figcaption>
still appears.the_advanced_excerpt('length=380&no_custom=1&no_shortcode=1&exclude_tags=figure,img,figcaption')
Is it possible to exclude the captions of image blocks from the excerpt?In your code you apply
$text = apply_filters( 'the_content', $text );
. In this filter the functiondo_blocks()
extracts the caption text via functionrender_block()
. Neverthelessrender_block()
provides a filter to short-circuit the rendering. Maybe you could hook into it to prevent the addition of the image captions.Currently I’ve solved this by adding a filter function which hooks into
render_block()
before the call ofthe_advanced_excerpt()
and removing it after the call again.
- The topic ‘Gutenberg: Captions from image blocks included in excerpt’ is closed to new replies.