Skip to content

feat(yoast): use shared primary category utility from newspack-plugin#2655

Merged
rbcorrales merged 1 commit intotrunkfrom
feat/use-shared-primary-category
Mar 26, 2026
Merged

feat(yoast): use shared primary category utility from newspack-plugin#2655
rbcorrales merged 1 commit intotrunkfrom
feat/use-shared-primary-category

Conversation

@rbcorrales
Copy link
Copy Markdown
Member

All Submissions:

Changes proposed in this Pull Request:

Replaces inline Yoast WPSEO_Primary_Term logic in the classic theme with the shared Newspack\Primary_Category utility from newspack-plugin (see Automattic/newspack-plugin#4563).

Changes:

  • newspack_categories() in template-tags.php now calls the shared utility with a class_exists guard, falling back to all categories when the plugin is not active
  • Body class logic in template-functions.php uses the shared utility for the primary-cat-* class
  • Removed the post_primary_category Customizer toggle (the setting now lives in Newspack > Settings > Advanced Settings)

The plugin handles backwards compatibility: sites that had the old Customizer toggle disabled will remain disabled until an admin explicitly changes it via the new settings UI, at which point the legacy theme mod is cleaned up.

Depends on Automattic/newspack-plugin#4563.

Closes NPPD-1346.

How to test the changes in this Pull Request:

  1. Activate the classic Newspack theme with Yoast SEO and newspack-plugin (with PR #4563) active.
  2. Create a post with multiple categories, set one as primary via Yoast.
  3. View the post. Only the primary category should display.
  4. Go to Newspack > Settings > Advanced Settings. Toggle off. View the post. All categories should display.
  5. Deactivate newspack-plugin entirely. View the post. All categories should display (graceful fallback).
  6. Verify the Customizer no longer shows the "Use Yoast's primary category functionality" checkbox.

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?

Copy link
Copy Markdown
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 updates the classic Newspack theme’s Yoast primary category handling to use the shared Newspack\Primary_Category utility provided by newspack-plugin, and removes the now-relocated Customizer toggle.

Changes:

  • Updated newspack_categories() to use Newspack\Primary_Category::get() when available, falling back to the standard category list otherwise.
  • Updated newspack_body_classes() to add the primary-cat-* class using the shared utility when available.
  • Removed the legacy post_primary_category Customizer setting/control.

Reviewed changes

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

File Description
newspack-theme/inc/template-tags.php Uses Newspack\Primary_Category when available; otherwise falls back to get_the_category_list().
newspack-theme/inc/template-functions.php Computes primary-cat-* body class via the shared utility when available.
newspack-theme/inc/customizer.php Removes the old Customizer toggle for Yoast primary category behavior.

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

@rbcorrales rbcorrales marked this pull request as ready for review March 24, 2026 08:24
@rbcorrales rbcorrales requested a review from a team as a code owner March 24, 2026 08:24
@rbcorrales rbcorrales added the [Status] Needs Review The issue or pull request needs to be reviewed label Mar 24, 2026
Copy link
Copy Markdown
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.

Looks good! That Customizer panel is getting empty!

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Mar 26, 2026
@rbcorrales rbcorrales merged commit 21908d7 into trunk Mar 26, 2026
11 checks passed
@rbcorrales rbcorrales deleted the feat/use-shared-primary-category branch March 26, 2026 02:51
@github-actions
Copy link
Copy Markdown

Hey @rbcorrales, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

matticbot pushed a commit that referenced this pull request Apr 2, 2026
# [2.21.0-alpha.1](v2.20.2...v2.21.0-alpha.1) (2026-04-02)

### Bug Fixes

* **layout:** prevent horizontal scrollbar on full-bleed image positions ([#2667](#2667)) ([c92383b](c92383b))
* **post-date:** move hook inside posted_on for markup preservation ([#2658](#2658)) ([fe6725a](fe6725a))

### Features

* **yoast:** use shared primary category utility from newspack-plugin ([#2655](#2655)) ([21908d7](21908d7))
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

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

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Apr 13, 2026
# [2.21.0](v2.20.3...v2.21.0) (2026-04-13)

### Bug Fixes

* **layout:** prevent horizontal scrollbar on full-bleed image positions ([#2667](#2667)) ([c92383b](c92383b))
* **post-date:** move hook inside posted_on for markup preservation ([#2658](#2658)) ([fe6725a](fe6725a))

### Features

* **yoast:** use shared primary category utility from newspack-plugin ([#2655](#2655)) ([21908d7](21908d7))
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 2.21.0 🎉

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

Labels

released on @alpha released [Status] Approved The pull request has been reviewed and is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants