Skip to content

Fix: Update post-publish panel to use taxonomy label instead of hardcoded "Tags" #70410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

shrivastavanolo
Copy link
Contributor

What?

Fixes #22588

Updates the MaybeTagsPanel component in the post-publish panel to use the dynamic taxonomy label for the post_tag taxonomy instead of hardcoded strings like "Tags".

Why?

Previously, the post-publish panel used hardcoded "Tags" strings in its UI, even if the taxonomy_labels_post_tag filter was used to rename the taxonomy (e.g., to "Keywords"). This led to inconsistencies between the main editor sidebar (which showed the correct custom label) and the pre-publish panel (which did not).

This PR resolves that by fetching the labels.name from the core data store via useSelect and using it in all strings via sprintf().

How?

  • Introduced a useSelect call to get the name label of the post_tag taxonomy.
  • Replaced all hardcoded “Tags” strings with sprintf() calls that dynamically insert the taxonomy label.

Testing Instructions

  1. Add something like the following to a plugin or your themes functions.php file.
add_filter(
	'taxonomy_labels_post_tag',
	function( object $labels ): object {
		$singular_name = 'Keyword';
		$plural_name   = 'Keywords';
		return (object) [
			'name'                  => $plural_name,
			'singular_name'         => $singular_name,
			'menu_name'             => $plural_name,
			'all_items'             => "All {$plural_name}",
			'new_item_name'         => "New {$singular_name} Name",
			'add_new_item'          => "Add New {$singular_name}",
			'edit_item'             => "Edit {$singular_name}",
			'update_item'           => "Update {$singular_name}",
			'view_item'             => "View {$singular_name}",
			'add_or_remove_items'   => "Add or remove {$plural_name}",
			'search_items'          => "Search {$plural_name}",
			'not_found'             => "No {$plural_name} found",
			'no_terms'              => "No {$plural_name}",
			'items_list'            => "{$plural_name} list",
			'items_list_navigation' => "{$plural_name} list navigation",
		];
	}
);
  1. Create a new post using Gutenberg.
  2. See that "tags" are changed to "keywords" in the sidebar.
  3. Don't add any tags/keywords before clicking on publish (and make sure to have the pre publish checks enabled). See that it says "Add Keywords" and "Keywords help users and search engines..." instead of "Add tags" etc. now

Screenshots or screencast

Before

Screenshot 2025-06-13 at 1 07 36 PM

After

Screenshot 2025-06-13 at 2 00 51 PM

@shrivastavanolo shrivastavanolo changed the title Fix post-publish panel to use taxonomy label instead of hardcoded "Tags" Fix: Update post-publish panel to use taxonomy label instead of hardcoded "Tags" Jun 13, 2025
@shrivastavanolo shrivastavanolo marked this pull request as ready for review June 13, 2025 09:51
Copy link

github-actions bot commented Jun 13, 2025

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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @ShreyaShrivastava@192.168.1.12, @lakrisgubben.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: shreyashrivastava@192.168.1.12, lakrisgubben.

Co-authored-by: shrivastavanolo <shreya0shrivastava@git.wordpress.org>
Co-authored-by: yogeshbhutkar <yogeshbhutkar@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: kathrynwp <zoonini@git.wordpress.org>
Co-authored-by: skorasaurus <skorasaurus@git.wordpress.org>

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

Copy link
Contributor

@yogeshbhutkar yogeshbhutkar left a comment

Choose a reason for hiding this comment

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

Works as advertised.

after

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Package] Editor /packages/editor labels Jun 16, 2025
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I think we should respect the add_new_item field instead of using the taxonomy name itself.

Example:

const Test = () => {
	const taxonomyLabels = useSelect( ( select ) => {
		const taxonomy = select( coreStore ).getTaxonomy( 'post_tag' );
		return taxonomy?.labels;
	}, [] );
	return taxonomyLabels?.add_new_item ?? __( 'Add tag' );
};

@t-hamano t-hamano added the General Interface Parts of the UI which don't fall neatly under other labels. label Jun 16, 2025
@shrivastavanolo
Copy link
Contributor Author

shrivastavanolo commented Jun 16, 2025

@t-hamano thanks for the review! Yeah, that makes sense. I changed the code to use add_new_items like so -

  1. Default tag labels:
Screenshot 2025-06-16 at 6 13 13 PM
  1. Modified tag labels ( add_new_item -> 'Add New Keyword' ):
Screenshot 2025-06-16 at 6 13 39 PM

Do you think it'll be better to convert panelBodyTitle to sentence case/title case before displaying or just to respect the case?

@t-hamano
Copy link
Contributor

@shrivastavanolo

Do you think it'll be better to convert "panelBodyTitle" to sentence case/title case before displaying or just to respect the case?

I don't recommend controlling the character case programmatically because it won't work properly in non-English locales.

Additionally, I don't need to use add_new_item in the description - we'll need to use the name property on the description to keep the original text, i.e. Tags help... instead of Add tag to help....

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

LGTM!

@t-hamano t-hamano merged commit de11ef9 into WordPress:trunk Jun 17, 2025
58 of 60 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.1 milestone Jun 17, 2025
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
…oded "Tags" (WordPress#70410)

* refactor: use tags taxonomy name label instead of hardcoded tags string in Maybe tags panel

* refactor: use add_new_item instead of name for taxonomy label

* refactor: use add_new_item label for panel title

* i18n: add i18n for static labels

---------

Unlinked contributors: shreyashrivastava@192.168.1.12, lakrisgubben.

Co-authored-by: shrivastavanolo <shreya0shrivastava@git.wordpress.org>
Co-authored-by: yogeshbhutkar <yogeshbhutkar@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: kathrynwp <zoonini@git.wordpress.org>
Co-authored-by: skorasaurus <skorasaurus@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
General Interface Parts of the UI which don't fall neatly under other labels. [Package] Editor /packages/editor [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maybe tags panel using hardcoded "tags" string instead of tags taxonomy name label
3 participants