Make WordPress Core

Opened 5 months ago

Last modified 3 months ago

#65111 new enhancement

Twenty Sixteen: Center text in image captions

Reported by: gaelbonithon Owned by:
Priority: normal Milestone: Awaiting Review
Component: Bundled Theme Version: 4.4
Severity: normal Keywords: has-patch close 2nd-opinion needs-refresh
Cc: Focuses: css

Description

It seems to me that this would be a better default choice. Ideally, we should be able to change it via the UI, but as far as I know, that’s not possible at the moment. One workaround is to use a centered paragraph via the code editor, which feels like a hack.

Attachments (1)

image-block-style-text-center.png (99.2 KB ) - added by sabernhardt 4 months ago.
Block style variation for centering caption text in the theme

Download all attachments as: .zip

Change History (10)

This ticket was mentioned in PR #11624 on WordPress/wordpress-develop by @gaelbonithon.


5 months ago
#1

  • Keywords has-patch added

It seems to me that this would be a better default choice. Ideally, we should be able to change it via the UI, but as far as I know, that's not possible at the moment. One workaround is to use a centered paragraph via the code editor, which feels like a hack.

Trac ticket: https://core.trac.wordpress.org/ticket/65111

## Use of AI Tools

#2 @manhar
5 months ago

Tested with patch and it is working as expected.

Refer below images :

Before Patch :
https://postimg.cc/wRN8Tdr9

After Patch :
https://postimg.cc/TyKkXJFY

#3 follow-up: @sabernhardt
5 months ago

  • Keywords close added
  • Version trunk4.4

The default styling probably should not change after the theme has been publicly available (for ten years). In this case, the theme documentation even shows the image caption text aligned to the left (in a left-to-right language).

The Gutenberg repository has an old issue about adding text alignment controls for captions:
https://github.com/WordPress/gutenberg/issues/12997

#4 in reply to: ↑ 3 @gaelbonithon
5 months ago

Replying to sabernhardt:

The default styling probably should not change after the theme has been publicly available (for ten years). In this case, the theme documentation even shows the image caption text aligned to the left (in a left-to-right language).

The Gutenberg repository has an old issue about adding text alignment controls for captions:
https://github.com/WordPress/gutenberg/issues/12997

Yes, I understand, thanks for the pointer. I'll leave it to you to close the ticket/PR…

#5 @sabernhardt
4 months ago

  • Keywords 2nd-opinion added

I almost closed the ticket, but I thought of another possibility to consider first.

To add a control for the user to select text alignment, a block style variation could be added in twentysixteen_setup().

register_block_style(
	'core/image',
	array(
		'name'         => 'caption-center',
		'label'        => __( 'Text align center', 'twentysixteen' ),
		'inline_style' => '.wp-block-image.is-style-caption-center figcaption { text-align: center; }',
	)
);

It still would not be available for someone who wants the Rounded style, and it is not as efficient as creating a control for use with any theme (GB12997).

@sabernhardt
4 months ago

Block style variation for centering caption text in the theme

#6 @gaelbonithon
4 months ago

Yeah, that would be nice, although it would obviously be better to have that option regardless of the theme (along with the other alignment options, at least right-aligned). Patch updated.

#7 follow-up: @poena
4 months ago

  • Keywords needs-refresh added

Using a block style is a good suggestion.

@gaelbonithon I would suggest moving the registration outside of the theme setup and use the init hook.
register_block_style was introduced in WP 5.3, and Twenty Sixteen supports WP version 4.4, so it needs to be wrapped in an if ( function_exists( 'register_block_style' ) ) { condition, please see Twenty Thirteen for an example.

#8 in reply to: ↑ 7 @gaelbonithon
4 months ago

Replying to poena:

Using a block style is a good suggestion.

@gaelbonithon I would suggest moving the registration outside of the theme setup and use the init hook.
register_block_style was introduced in WP 5.3, and Twenty Sixteen supports WP version 4.4, so it needs to be wrapped in an if ( function_exists( 'register_block_style' ) ) { condition, please see Twenty Thirteen for an example.

Thanks for review, patch updated. I added @since Twenty Sixteen 3.9 based on readme.txt; I hope that's correct.

#9 @ankitkumarshah
3 months ago

I tested the updated PR and confirmed that it successfully adds the block style variation for centering image caption text in Twenty Sixteen.

The implementation works as expected on my end.

Screenshot:

https://i.postimg.cc/Dwr55pGX/Screenshot-2026-05-28-at-7-20-30-PM.png

Note: See TracTickets for help on using tickets.