feat: add featured image caption block#415
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new custom block for displaying featured image captions with optional media credit information. The block integrates with the Newspack Image Credits plugin to automatically display caption and credit metadata, while also allowing users to override with custom caption text.
Changes:
- Added a new
newspack-block-theme/featured-image-captionblock with editor UI and server-side rendering - Integrated the block into all post and archive templates that display featured images
- Implemented support for automatic caption/credit display from media metadata with custom override capability
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| includes/blocks/featured-image-caption/class-featured-image-caption.php | PHP class for block registration and server-side rendering |
| includes/blocks/featured-image-caption/block.json | Block metadata and configuration |
| includes/blocks/featured-image-caption/edit.js | React component for block editor UI |
| includes/blocks/featured-image-caption/editor.js | Block registration entry point |
| includes/blocks/featured-image-caption/style.scss | Styles for placeholder text in editor |
| includes/blocks/index.php | Added require statement to load new block class |
| src/scss/blocks/_blocks.scss | Added import for block styles |
| templates/single/*.html | Added featured-image-caption block to all single post templates |
| templates/archive.html | Added featured-image-caption block to archive template |
| templates/author.html | Added featured-image-caption block to author template |
| templates/home.html | Added featured-image-caption block to home template |
| templates/search.html | Added featured-image-caption block to search template |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
includes/blocks/featured-image-caption/class-featured-image-caption.php
Outdated
Show resolved
Hide resolved
includes/blocks/featured-image-caption/class-featured-image-caption.php
Outdated
Show resolved
Hide resolved
includes/blocks/featured-image-caption/class-featured-image-caption.php
Outdated
Show resolved
Hide resolved
c175571 to
d78c2f4
Compare
laurelfulford
left a comment
There was a problem hiding this comment.
This is awesome, @chickenn00dle! I added some feedback ahead of splitting this out into the Newspack Plugin repo. I totally get if it's a pain to have that here, so let me know if I should just copy things over after it's been moved 🙂
This is a bit of an edge case, but when I add a featured image block + caption block to a post's/page's content, the placeholder for the caption is empty in the editor:
The correct caption displays in the published page/post.
If the caption has been customized, the customized text will appear, but the credit no longer shows with it.
| return ( | ||
| <figcaption { ...blockProps }> | ||
| <span className="featured-image-caption-placeholder"> | ||
| { __( 'Select a featured image or add a featured image block to add a caption.', 'newspack-block-theme' ) } |
There was a problem hiding this comment.
This is probably a good one to get @thomasguillot's eyes on, but I think the placeholder should be non-italicized, to match how other text placeholders are in the blocks.
I'm not entirely sure about the placeholder text -- it shows this in the Site Editor even when there's a Featured Image already there. It's not as helpful outside of the Site Editor, but maybe just "Featured image caption"? (Also open to feedback on that!)
There was a problem hiding this comment.
I removed the italics and updated the caption placeholder text when moving this to Automattic/newspack-plugin#4519
| "typography": { | ||
| "fontSize": true, | ||
| "lineHeight": true, | ||
| "textAlign": true |
There was a problem hiding this comment.
I think it might be good (in theory at least!) to support changing fonts/font styles where we can. It'd be a little weird for one-offs, but it could be handy for changes in the Site Editor/in specific templates:
| "textAlign": true | |
| "textAlign": true, | |
| "__experimentalFontFamily": true, | |
| "__experimentalFontWeight": true, | |
| "__experimentalFontStyle": true, | |
| "__experimentalTextTransform": true, | |
| "__experimentalTextDecoration": true, | |
| "__experimentalLetterSpacing": true, | |
| "__experimentalDefaultControls": { | |
| "fontSize": true, | |
| "fontAppearance": true | |
| } |
There was a problem hiding this comment.
Good call! Added in the new PR Automattic/newspack-plugin#4519
templates/single.html
Outdated
| <!-- wp:group {"metadata":{"name":"Post Image"},"align":"full","className":"post-image","style":{"spacing":{"margin":{"top":"var:preset|spacing|80","bottom":"var:preset|spacing|80"}}},"layout":{"type":"constrained"}} --> | ||
| <div class="wp-block-group alignfull post-image" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"> | ||
| <!-- wp:post-featured-image /--> | ||
| <!-- wp:newspack-block-theme/featured-image-caption /--> |
There was a problem hiding this comment.
This'll need to be fine-tuned per template (and is something that could use @thomasguillot's eyes), but I think the image + caption should be wrapped in a 'stack' block, and have the block spacing adjusted:
Something like this:
There was a problem hiding this comment.
Happy to change this later based on feedback, but for now added the stacks in github.com//pull/415/commits/ffd17797bf8a3a891541c3e4656def647265bebd
includes/blocks/index.php
Outdated
| defined( 'ABSPATH' ) || exit; | ||
|
|
||
| require_once NEWSPACK_BLOCK_THEME_FILE_PATH . '/includes/blocks/subtitle-block/class-subtitle-block.php'; | ||
| require_once NEWSPACK_BLOCK_THEME_FILE_PATH . '/includes/blocks/featured-image-caption/class-featured-image-caption.php'; |
There was a problem hiding this comment.
There will be an established pattern in the Newspack Plugin to follow for this, but we've been restricting these new blocks to just block themes, since they make less sense to use with the classic theme.
| require_once NEWSPACK_BLOCK_THEME_FILE_PATH . '/includes/blocks/featured-image-caption/class-featured-image-caption.php'; | |
| if ( wp_is_block_theme() ) { | |
| require_once NEWSPACK_BLOCK_THEME_FILE_PATH . '/includes/blocks/featured-image-caption/class-featured-image-caption.php'; | |
| } |
There was a problem hiding this comment.
Thanks! This check was actually not required when the block lived in this repo since it would only be available when the block theme was active, but I made sure to move this behind this check in the plugin PR after moving it there: Automattic/newspack-plugin#4519
4696d21 to
ffd1779
Compare
|
Thanks for the review @laurelfulford! I moved the block over to the plugin repo and applied your feedback there: Automattic/newspack-plugin#4519 This PR should now just contain changes to the block theme templates. |
laurelfulford
left a comment
There was a problem hiding this comment.
Thanks @chickenn00dle! All the placements look good!
ffd1779 to
78f44f6
Compare
# [1.26.0-alpha.1](v1.25.0...v1.26.0-alpha.1) (2026-03-05) ### Features * add AGENTS.md and CLAUDE.md; update README.md ([#420](#420)) ([7494928](7494928)) * add featured image caption block to templates ([#415](#415)) ([7db45fe](7db45fe)) * add new styles ([#416](#416)) ([37e82db](37e82db)) * remove newspack-grid, newspack-grid-small, newspack-grid-sidebar ([#417](#417)) ([86b8292](86b8292)) * use dynamic copyright date block in footer patterns ([#414](#414)) ([22c9bc8](22c9bc8))
|
🎉 This PR is included in version 1.26.0-alpha.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
All Submissions:
Changes proposed in this Pull Request:
Closes https://linear.app/a8c/issue/NPPD-1187/captioncredit-block-for-featured-images
This PR adds the featured image caption block to various templates across the theme
How to test the changes in this Pull Request:
To test, be sure to also checkout Automattic/newspack-plugin#4519
View the following templates in the site editor and confirm the new featured image caption block is added:
Other information: