我尝试获取古腾堡媒体库块输出,并希望对图像标题使用默认的figcaption文本功能(对于js lightbox)。如何获取此属性figcaption文本值?
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 );