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

1.0.0 2026-02-24 14:58 UTC

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

  1. The block automatically detects the post ID from context
  2. If Yoast SEO is active, it uses the primary category set by Yoast
  3. For posts with multiple categories, it returns the top-level parent category
  4. 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

  1. Clone this repository to your WordPress plugins directory
  2. Run npm install to install dependencies
  3. Run npm run build to build the block
  4. Activate the plugin in WordPress

Development

  • npm start - Start development mode with hot reload
  • npm run build - Build production files
  • npm 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,

  1. Review the unreleased features in the Changelog and choose the target version number for the next release using semantic versioning
  2. Checkout a prepare-v#.#.# branch. In that branch,
  3. Open a pull request from your branch titled "Prepare release v#.#.#"
  4. Review and merge your "Prepare release" pull request
  5. Wait for the release branch to update with the build that includes the new version number
  6. 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.php and your newest Changelog section
      • Use the format v#.#.# for your version tag
    • 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"

Screenshot of Run workflow dropdown form being filled out

Once the workflow completes, your new version should be tagged and available in the list of releases

License

GPL-2.0-or-later