I try to get gutenberg media gallery block output, and want to use default figcaption text feature for images titles (for js lightbox). How can i get this property figcaption text value?
add_filter( 'render_block', function( $block_content, $block ) {
if ( 'core/gallery' !== $block['blockName'] || ! isset( $block['attrs']['ids'] ) ) {
return $block_content;
}
$li = '';
foreach( (array) $block['attrs']['ids'] as $id ) {
$li .= sprintf( '<li><a href="%s" data-lightbox="photo" data-title="%s"><img src="%s" class="w-100"></a></li>',
wp_get_attachment_image_src( $id, '' )[0],
'FIGCAPTION TEXT',
wp_get_attachment_image_src( $id, 'thumbnail' )[0] );
}
return sprintf( '<ul id="gallery-grid">%s</ul>', $li );
}, 10, 2 );