humanmade / hm-primary-category-block
Displays the primary category for a post.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 1
Type:wordpress-plugin
pkg:composer/humanmade/hm-primary-category-block
Requires
- php: >=8.2
This package is auto-updated.
Last update: 2026-02-24 16:37:43 UTC
README
Displays the primary category for a post in the WordPress block editor.
Features
- Displays the primary category for a post
- Supports Yoast SEO primary category selection
- Server-side rendered for optimal performance
Usage
The Primary Category block is automatically available after plugin activation. The block uses the postId context and is typically used within:
- Query Loop blocks
- Post Templates
- Single post layouts
How it works
- The block automatically detects the post ID from context
- If Yoast SEO is active, it uses the primary category set by Yoast
- For posts with multiple categories, it returns the top-level parent category
- For single category posts, it returns that category
Block Name
The block is registered as hm/primary-category and can be inserted programmatically or used in block patterns.
Customization
The block outputs a link with the class hentry__category which can be styled via CSS:
.hentry__category { /* Your custom styles */ }
Installation
- Clone this repository to your WordPress plugins directory
- Run
npm installto install dependencies - Run
npm run buildto build the block - Activate the plugin in WordPress
Development
npm start- Start development mode with hot reloadnpm run build- Build production filesnpm run lint- Run linters
Requirements
- WordPress 6.0+
- PHP 8.2+
- Node.js 22+
Release Process
Merges to main will automatically build to the release branch. A project may be set up to track the release branch using composer to pull in the latest built beta version.
Commits on the release branch may be tagged for installation via packagist and marked as releases in GitHub for manual download using a manually-dispatched "Tag and Release" GH Actions workflow.
To tag a new release,
- Review the unreleased features in the Changelog and choose the target version number for the next release using semantic versioning
- Checkout a
prepare-v#.#.#branch. In that branch,- Add a new header into CHANGELOG.md for any unreleased features
- Bump the version number in the hm-primary-category-block.php file's PHPDoc header
- Open a pull request from your branch titled "Prepare release v#.#.#"
- Review and merge your "Prepare release" pull request
- Wait for the
releasebranch to update with the build that includes the new version number - On the "Tag and Release" GH Action page],
- Click the "Run workflow" button in the "workflow_dispatch" notification banner (see screenshot below)
- Fill out the "Version tag" field with your target version number
- This version must match the version in
hm-primary-category-block.phpand your newest Changelog section - Use the format
v#.#.#for your version tag
- This version must match the version in
- Leave the "Branch to tag" field as
release(we will add the tag on the release branch containing the latest built code) - Click "Run workflow"
Once the workflow completes, your new version should be tagged and available in the list of releases
License
GPL-2.0-or-later
