+
"
diff --git a/packages/block-library/src/media-text/block.json b/packages/block-library/src/media-text/block.json
index 0c2cfc4a14995..56aca99df87b7 100644
--- a/packages/block-library/src/media-text/block.json
+++ b/packages/block-library/src/media-text/block.json
@@ -96,6 +96,12 @@
"useFeaturedImage": {
"type": "boolean",
"default": false
+ },
+ "caption": {
+ "type": "rich-text",
+ "source": "rich-text",
+ "selector": "figcaption",
+ "role": "content"
}
},
"usesContext": [ "postId", "postType" ],
diff --git a/packages/block-library/src/media-text/edit.js b/packages/block-library/src/media-text/edit.js
index 820c792730311..a2fd5da81ef90 100644
--- a/packages/block-library/src/media-text/edit.js
+++ b/packages/block-library/src/media-text/edit.js
@@ -76,6 +76,7 @@ function attributesFromMedia( {
mediaLink: undefined,
href: undefined,
focalPoint: undefined,
+ caption: undefined,
useFeaturedImage: false,
} );
return;
@@ -129,6 +130,7 @@ function attributesFromMedia( {
mediaLink: media.link || undefined,
href: newHref,
focalPoint: undefined,
+ caption: media.caption,
useFeaturedImage: false,
} );
};
@@ -185,6 +187,7 @@ function MediaTextEdit( {
verticalAlignment,
allowedBlocks,
useFeaturedImage,
+ caption,
} = attributes;
const [ featuredImage ] = useEntityProp(
@@ -228,6 +231,9 @@ function MediaTextEdit( {
const featuredImageAlt = useFeaturedImage
? featuredImageMedia?.alt_text
: '';
+ const featuredImageCaption = useFeaturedImage
+ ? featuredImageMedia?.caption?.rendered
+ : '';
const toggleUseFeaturedImage = () => {
setAttributes( {
@@ -512,6 +518,7 @@ function MediaTextEdit( {
refMedia={ refMedia }
enableResize={ blockEditingMode === 'default' }
toggleUseFeaturedImage={ toggleUseFeaturedImage }
+ setAttributes={ setAttributes }
{ ...{
focalPoint,
imageFill,
@@ -526,6 +533,9 @@ function MediaTextEdit( {
useFeaturedImage,
featuredImageURL,
featuredImageAlt,
+ caption: useFeaturedImage
+ ? featuredImageCaption
+ : caption,
} }
/>
{ mediaPosition !== 'right' &&
}
diff --git a/packages/block-library/src/media-text/index.php b/packages/block-library/src/media-text/index.php
index b65137b150ba5..9a0e5a3568a5d 100644
--- a/packages/block-library/src/media-text/index.php
+++ b/packages/block-library/src/media-text/index.php
@@ -79,6 +79,11 @@ function render_block_core_media_text( $attributes, $content ) {
// in order to display the featured image.
$media_size_slug = isset( $attributes['mediaSizeSlug'] ) ? $attributes['mediaSizeSlug'] : 'full';
$image_tag = '
';
+ $caption = get_the_post_thumbnail_caption();
+ $image_tag .= sprintf(
+ '
%1$s',
+ $caption
+ );
$content = preg_replace(
'/(