Skip to content

feat: add support for displaying tags as labels#4381

Open
jason10lee wants to merge 14 commits intotrunkfrom
feat/tag-labels
Open

feat: add support for displaying tags as labels#4381
jason10lee wants to merge 14 commits intotrunkfrom
feat/tag-labels

Conversation

@jason10lee
Copy link
Contributor

@jason10lee jason10lee commented Jan 7, 2026

All Submissions:

Changes proposed in this Pull Request:

This PR is one of a set that adds the ability to display selected tags as labels. Changes live in the feat/tag-labels topic branch on the newspack-blocks, newspack-plugin, and newspack-theme projects.

See also: Automattic/newspack-theme#2613
See also: Automattic/newspack-blocks#2282

  1. In non-singular context (as part of a Content Loop block, for example), the tag label will show up in front of the headline.
  2. In singular context (on the individual post page, for example), the tag label will show up with the category label.

By default, the text of the tag label will be the same as the tag name. Optionally, the label text can be customized (e.g., to something shorter and more suitable for use as a label).

Labels will appear above the headline, after any category or sponsorship labels.

By default, the text of the tag label will be the same as the tag name. Optionally, the label text can be customized (e.g., to something shorter and more suitable for use as a label). Additionally, the label color can be customized in the Newspack Theme customizer.

Addresses NPPD-383: "Breaking News" or "Developing" Label.

How to test the changes in this Pull Request:

Basic operation:

  1. Pull this topic branch, the newspack-blocks topic branch, and the corresponding newspack-theme topic branch.
  2. Create a post tag. Name and description don't matter. Confirm that you see a 'Display as label' checkbox below the Add Tag form.
  3. Check the 'Display as label' checkbox. Confirm a 'Label text' field appears below the 'Display as Label' checkbox.
  4. Save the tag.
  5. Tag a post with your new tag.
  6. View the post and confirm the post now shows a label with the tag name on it just above the headline. You should see this on the home page (i.e., Content Loop block) and on the individual post page.
  7. Edit the post tag again. Uncheck the 'Display as label' checkbox. Confirm the 'Label text' field is disabled and save.
  8. Confirm the label is no longer shown on the post.

Multiple labels:

  1. Enable tag labels on your test tag, as above.
  2. Tag your test post with another tag that doesn't have labels enabled. Confirm only the test tag with labels enabled displays a label on the post.
  3. Enable labels on your second test tag. Confirm it also shows up on the post.

Custom label text (flag):

  1. Edit one of your test post tags. Check the 'Display as label' field to enable the 'Label text' field.
  2. Add text of your choice (something different from the tag name!) to the 'Label text' field and save.
  3. Confirm the test post shows a label with your custom text in all contexts.
  4. Edit the post tag and verify your custom text is still shown in the 'Label text' field.
  5. Clear the 'Label text' field. Confirm the original tag name is again shown as a placeholder and save.
  6. Confirm the test post shows a label with the original tag name.
  7. Edit the post tag, uncheck the 'Display as label' field and save. Confirm the label's no longer shown.
  8. Edit the post tag and add custom text to the 'Label text' field again. Save. (Optionally: check your custom text still shows up!)
  9. Edit the post tag and uncheck the 'Display as label' field. Confirm no label is shown on the test post.

Custom label color:

  1. Add a tag with labels enabled to a test post.
  2. Ensure you're using a Newspack theme, and open the theme customizer (Appearance > Customize).
  3. Select Tag Labels from the menu.
  4. Click on 'Select color' to select a color for the label. If a post tagged with that label is visible in the preview pane on the right, you should see it change! The text color may change as well to better contrast with the new label color.
  5. Hit the 'Publish' button at the top and check your test post. It should show the new color scheme.

Other information:

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

Copy link
Contributor

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 functionality to display selected post tags as labels, similar to how categories are displayed. The feature includes an admin interface for enabling tags as labels with optional custom label text, and works in conjunction with a companion PR in the newspack-theme repository.

  • Added a new Tag_Labels class that manages tag label settings via term meta
  • Created admin UI fields to enable tags as labels and customize label text
  • Added helper methods for themes to retrieve tag labels for display

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 14 comments.

File Description
src/other-scripts/tag-labels/index.js Adds jQuery-based client-side logic to enable/disable the label flag input based on checkbox state
includes/tag-labels/class-tag-labels.php Implements the core Tag_Labels class with admin UI, data storage, and helper methods for retrieving tag labels
includes/class-newspack.php Includes the new tag-labels class file to integrate it into the plugin

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jason10lee jason10lee marked this pull request as ready for review January 9, 2026 20:20
@jason10lee jason10lee requested a review from a team as a code owner January 9, 2026 20:20
@leogermani leogermani added the [Status] Needs Review The issue or pull request needs to be reviewed label Jan 13, 2026
Copy link
Contributor

@leogermani leogermani 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 looking good Jason, thanks for the work! I left some minor comments in the code.

I'll tag @thomasguillot and add a needs-design review for him to have a look and answer your questions around presentation. I think it should follow what Sponsors do as much as possible (which is to display the label above the title). Thomas, please also share your thought on how we name and present this feature in the UI. Is "Labels" a good name?

I also have an existencial question I'll copy for @laurelfulford : Since this is very tied to the theme, should this whole thing live in the theme instead? WDYT?

@thomasguillot
Copy link
Contributor

Create a post tag. Name and description don't matter.
Edit the post tag. Confirm that you see both a 'Use as label' checkbox and a (disabled) 'Label flag' field below it.

How come we don't have the checkbox and the label flag field when first creating? I must admit I thought I hadn't switched branch and it wasn't working at first.

@jason10lee
Copy link
Contributor Author

Create a post tag. Name and description don't matter.
Edit the post tag. Confirm that you see both a 'Use as label' checkbox and a (disabled) 'Label flag' field below it.

How come we don't have the checkbox and the label flag field when first creating? I must admit I thought I hadn't switched branch and it wasn't working at first.

Thanks, @thomasguillot! That was a potential issue I flagged, and based on your and @leogermani's comments, I think it'll be worth making those options visible on creation.

@thomasguillot
Copy link
Contributor

"Labels" works well. It's intuitive, distinct from the existing "Tags" terminology, and commonly understood in editorial contexts I think.

For the fields, I'd suggest: (ae531b4)

Checkbox: "Display as label" with help text: Show this tag as a highlighted label wherever posts are displayed.
Text input: "Label text" with help text: Custom text to display instead of the tag name.

@jason10lee
Copy link
Contributor Author

jason10lee commented Jan 16, 2026

For the fields, I'd suggest: (ae531b4)

All good, and I'll be using the tweaks you made to the dependent field toggles for the add_form_fields side of things, too!

Copy link
Contributor

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

jason10lee and others added 2 commits January 23, 2026 18:32
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jason10lee jason10lee requested a review from leogermani January 26, 2026 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Needs Design Review [Status] Needs Review The issue or pull request needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants