diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md
index 7e031fa525e1ff..c6088a512107b2 100644
--- a/docs/reference-guides/core-blocks.md
+++ b/docs/reference-guides/core-blocks.md
@@ -445,7 +445,7 @@ Set media and words side-by-side for a richer layout. ([Source](https://github.c
- **Name:** core/media-text
- **Category:** media
- **Supports:** align (full, wide), anchor, color (background, gradients, heading, link, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
-- **Attributes:** align, allowedBlocks, focalPoint, href, imageFill, isStackedOnMobile, linkClass, linkDestination, linkTarget, mediaAlt, mediaId, mediaLink, mediaPosition, mediaSizeSlug, mediaType, mediaUrl, mediaWidth, rel, useFeaturedImage, verticalAlignment
+- **Attributes:** align, allowedBlocks, caption, focalPoint, href, imageFill, isStackedOnMobile, linkClass, linkDestination, linkTarget, mediaAlt, mediaId, mediaLink, mediaPosition, mediaSizeSlug, mediaType, mediaUrl, mediaWidth, rel, useFeaturedImage, verticalAlignment
## Unsupported
diff --git a/packages/block-library/src/media-text/block.json b/packages/block-library/src/media-text/block.json
index 0c2cfc4a14995a..56aca99df87b76 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 a946a499b26f21..9d99e02a5d07a1 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,
} );
return;
}
@@ -128,6 +129,7 @@ function attributesFromMedia( {
mediaLink: media.link || undefined,
href: newHref,
focalPoint: undefined,
+ caption: media.caption,
} );
};
}
@@ -156,6 +158,7 @@ function MediaTextEdit( {
verticalAlignment,
allowedBlocks,
useFeaturedImage,
+ caption,
} = attributes;
const mediaSizeSlug = attributes.mediaSizeSlug || DEFAULT_MEDIA_SIZE_SLUG;
@@ -179,6 +182,9 @@ function MediaTextEdit( {
const featuredImageAlt = useFeaturedImage
? featuredImageMedia?.alt_text
: '';
+ const featuredImageCaption = useFeaturedImage
+ ? featuredImageMedia?.caption?.rendered
+ : '';
const toggleUseFeaturedImage = () => {
setAttributes( {
@@ -483,6 +489,7 @@ function MediaTextEdit( {
refMedia={ refMedia }
enableResize={ blockEditingMode === 'default' }
toggleUseFeaturedImage={ toggleUseFeaturedImage }
+ setAttributes={ setAttributes }
{ ...{
focalPoint,
imageFill,
@@ -497,6 +504,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 b65137b150ba53..9a0e5a3568a5d8 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(
'/(