Skip to content

feat: add featured image caption block#415

Merged
chickenn00dle merged 8 commits intotrunkfrom
feat/add-featured-image-caption-block
Mar 3, 2026
Merged

feat: add featured image caption block#415
chickenn00dle merged 8 commits intotrunkfrom
feat/add-featured-image-caption-block

Conversation

@chickenn00dle
Copy link
Contributor

@chickenn00dle chickenn00dle commented Feb 18, 2026

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:

  • archive
  • author
  • home
  • search
  • single
  • single/50-50-image
  • single/full-width-image
  • single/large-image
  • single/sidebar-layout
  • single/wide-image

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@chickenn00dle chickenn00dle marked this pull request as ready for review February 18, 2026 21:29
@chickenn00dle chickenn00dle requested a review from a team as a code owner February 18, 2026 21:29
Copilot AI review requested due to automatic review settings February 18, 2026 21:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-caption block 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.

Copy link
Contributor

@laurelfulford laurelfulford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Image

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' ) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
"textAlign": true
"textAlign": true,
"__experimentalFontFamily": true,
"__experimentalFontWeight": true,
"__experimentalFontStyle": true,
"__experimentalTextTransform": true,
"__experimentalTextDecoration": true,
"__experimentalLetterSpacing": true,
"__experimentalDefaultControls": {
"fontSize": true,
"fontAppearance": true
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! Added in the new PR Automattic/newspack-plugin#4519

<!-- 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 /-->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Image

Something like this:

Image Image Image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to change this later based on feedback, but for now added the stacks in github.com//pull/415/commits/ffd17797bf8a3a891541c3e4656def647265bebd

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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';
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@chickenn00dle chickenn00dle force-pushed the feat/add-featured-image-caption-block branch 2 times, most recently from 4696d21 to ffd1779 Compare February 26, 2026 17:38
@chickenn00dle
Copy link
Contributor Author

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.

Copy link
Contributor

@laurelfulford laurelfulford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chickenn00dle! All the placements look good!

@chickenn00dle chickenn00dle force-pushed the feat/add-featured-image-caption-block branch from ffd1779 to 78f44f6 Compare March 3, 2026 15:52
@chickenn00dle chickenn00dle merged commit 7db45fe into trunk Mar 3, 2026
5 checks passed
@chickenn00dle chickenn00dle deleted the feat/add-featured-image-caption-block branch March 3, 2026 16:02
matticbot pushed a commit that referenced this pull request Mar 5, 2026
# [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))
@github-actions
Copy link

github-actions bot commented Mar 5, 2026

🎉 This PR is included in version 1.26.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants