Skip to content

Twenty Twenty: Fix post meta wrapper not rendering when action hooks add content without default meta - #11769

Open
shrivastavanolo wants to merge 2 commits into
WordPress:trunkfrom
shrivastavanolo:fix/twentytwenty-has-meta-hook
Open

shrivastavanolo wants to merge 2 commits into
WordPress:trunkfrom
shrivastavanolo:fix/twentytwenty-has-meta-hook

Conversation

@shrivastavanolo

@shrivastavanolo shrivastavanolo commented May 8, 2026 •

Copy link
Copy Markdown

twentytwenty_get_post_meta() uses a $has_meta flag to decide whether to return the meta wrapper HTML. This flag is only set to true when default meta fields (author, date, tags, etc.) are present. As a result, content added via thetwentytwenty_start_of_post_meta_list and twentytwenty_end_of_post_meta_list action hooks is silently discarded when no default meta exists — for example, on a post with no tags in the single-bottom location.

This fix checks whether the output buffer contains any content after stripping tags. The meta wrapper is now returned if either default meta or hook content is present.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude
Model(s): Opus 4.6
Used for: Initial code skeleton and PR description; final implementation and tests were reviewed and edited by me.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented May 8, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props shreya0shrivastava, sabernhardt, karmatosed.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Comment thread src/wp-content/themes/twentytwenty/inc/template-tags.php Outdated
@shrivastavanolo
shrivastavanolo force-pushed the fix/twentytwenty-has-meta-hook branch from fb47a6f to d8914be Compare May 13, 2026 09:04

@sabernhardt sabernhardt left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Test Report

Patch tested: https://github.com/WordPress/wordpress-develop/pull/11769.diff

Steps taken

  1. Activate Twenty Twenty.
  2. Create and publish two posts: one with at least one tag and one with zero tags.
  3. Use actions to add custom list items at beginning and end of the meta list.
  4. Add each filter example—or a combination of them—to change the default output.
  5. Reset the actions and filters.
  6. Apply the patch.
  7. Repeat steps 3 and 4 to test how the same actions and filters work with the patch.

Code samples

I added these in a custom must-use plugin, but you could test with a child theme.

// Add list items at beginning and end.
add_action( 'twentytwenty_start_of_post_meta_list', function() {
	echo '<li>twentytwenty_start_of_post_meta_list</li>';
});
add_action( 'twentytwenty_end_of_post_meta_list', function() {
	echo '<li>twentytwenty_end_of_post_meta_list</li>';
});

// Filter 1: Replace single-top meta with tags list.
add_filter( 'twentytwenty_post_meta_location_single_top', function() {
	return array( 'tags' );
});

// Filter 2: Replace single-bottom meta with 'sticky' (if the posts are *not* sticky).
add_filter( 'twentytwenty_post_meta_location_single_bottom', function() {
	return array( 'sticky' );
});

// Filters 3a +3b: Remove default meta in either location with 'foo' as a dummy array value.
add_filter( 'twentytwenty_post_meta_location_single_top', function() {
	return array( 'foo' );
});
add_filter( 'twentytwenty_post_meta_location_single_bottom', function() {
	return array( 'foo' );
});

// Filters 4a + 4b: Remove all post meta—even custom meta—from either location.
add_filter( 'twentytwenty_post_meta_location_single_top', '__return_empty_array' );
add_filter( 'twentytwenty_post_meta_location_single_bottom', '__return_empty_array' );

Screenshots

✅ With default post meta, the patch does not change the output.

Before patch With patch
default post meta, on a post with a tag, before patch default post meta, on a post with a tag, after patch
default post meta, on a post without any tags, before patch default post meta, on a post without any tags, after patch

When I added start and end list items in both locations, they appeared in the top and bottom except when the post had zero tags. With the patch, the custom list items display even when the post has no tags.

Before patch With patch
adding start and end list items in both locations, on a post with a tag, before patch adding start and end list items in both locations, on a post with a tag, after patch
adding start and end list items in both locations, on a post without any tags, before patch adding start and end list items in both locations, on a post without any tags, after patch

When I used array( 'tags' ) for meta in the top location, the custom list items similarly did not display before the patch when there were zero tags. Again, with the patch, the custom list items display even when the post has no tags.

Before patch With patch
replacing top meta with ‘tags’, on a post with a tag, before patch replacing top meta with ‘tags’, on a post with a tag, after patch
replacing top meta with ‘tags’, on a post without any tags, before patch replacing top meta with ‘tags’, on a post without any tags, after patch

When I used array( 'sticky' ) in the bottom location, after applying the patch, the custom list items displayed without showing anything else (because the posts were not sticky).

Before patch With patch
replacing bottom meta with ‘sticky’, on a post with a tag, before patch replacing bottom meta with ‘sticky’, on a post with a tag, after patch
replacing bottom meta with ‘sticky’, on a post without any tags, before patch replacing bottom meta with ‘sticky’, on a post without any tags, after patch

The screenshots below show results from setting array( 'tags' ) in the top location and array( 'sticky' ) in the bottom location, at the same time.

Before patch With patch
replacing top meta with ‘tags’ and bottom meta with ‘sticky’, on a post with a tag, before patch replacing top meta with ‘tags’ and bottom meta with ‘sticky’, on a post with a tag, after patch
replacing top meta with ‘tags’ and bottom meta with ‘sticky’, on a post without any tags, before patch replacing top meta with ‘tags’ and bottom meta with ‘sticky’, on a post without any tags, after patch

Using array( 'foo' ) removes any default meta, but the post shows any custom items with the patch applied. In the top location, that removes the author, date, comments, and possibly a note that the post is sticky.

Before patch With patch
dummy ‘foo’ array in top location, on a post with a tag, before patch dummy ‘foo’ array in top location, on a post with a tag, after patch
dummy ‘foo’ array in top location, on a post without any tags, before patch dummy ‘foo’ array in top location, on a post without any tags, after patch

array( 'foo' ) in the bottom location:

Before patch With patch
dummy ‘foo’ array in bottom location, on a post with a tag, before patch dummy ‘foo’ array in bottom location, on a post with a tag, after patch
dummy ‘foo’ array in bottom location, on a post without any tags, before patch dummy ‘foo’ array in bottom location, on a post without any tags, after patch

An empty array removes any meta, including custom items. These screenshots show the top location without any meta:

Before patch With patch
empty array in top location, on a post with a tag, before patch empty array in top location, on a post with a tag, after patch
empty array in top location, on a post without any tags, before patch empty array in top location, on a post without any tags, after patch

Empty array in the bottom location:

Before patch With patch
empty array in bottom location, on a post with a tag, before patch empty array in bottom location, on a post with a tag, after patch
empty array in bottom location, on a post without any tags, before patch empty array in bottom location, on a post without any tags, after patch

Environment

  • WordPress: 7.1-alpha-62161-src
  • Subdirectory: No
  • PHP: 8.3.14
  • Server: Apache/2.4.62 (Win64) PHP/8.3.14 mod_fcgid/2.3.10-dev
  • Database: mysqli (Server: 9.1.0 / Client: mysqlnd 8.3.14)
  • Browser: Firefox
  • OS: Windows 11
  • Theme: Twenty Twenty 3.1
  • MU Plugin: SVN

@karmatosed

Copy link
Copy Markdown
Member

This branch needs a refresh, if we can get that we can consider it.

shrivastavanolo and others added 2 commits October 19, 2026 12:27
Co-authored-by: Stephen A. Bernhardt <sabernhardt@yahoo.com>
@shrivastavanolo
shrivastavanolo force-pushed the fix/twentytwenty-has-meta-hook branch from d8914be to a81c4d4 Compare October 19, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants