Guide

Taxonomy List Link

Individual navigation link within a prc-block/taxonomy-list. Supports multiple variations including plain links, sub-headings, expandable sub-trees, and toggleable sub-expand menus. Uses the Interactivity API for active state management and URL-based state persistence.

Block inserter example

block.json defines an example with sample label / url — inserter preview (parent is taxonomy-list).

Namespace

prc-block/taxonomy-list-link

Category

theme

Supports

FeatureDetail
AnchorYes
HTMLNo
ColorText, link, background
InteractivityYes
Spacingmargin, padding, blockGap
TypographyfontSize, fontFamily, fontWeight, fontStyle, textTransform, textDecoration (skip serialization), letterSpacing, lineHeight

Attributes

AttributeTypeDefaultDescription
labelstringDisplay text for the link
urlstringLink destination URL
idintegerAssociated term ID
descriptionstringTerm description
relstringLink rel attribute
opensInNewTabbooleanWhether the link opens in a new browser tab
titlestringLink title attribute
taxonomystringTaxonomy slug (also received via context)
enableSubMenubooleanEnables sub-menu toggle behavior with expand/collapse

Available Styles / Variations

Four registered variations in variations.js:

VariationNameClassDescription
Link (default)taxonomy-menu-link-defaultStandard taxonomy term link
Sub Headingtaxonomy-menu-link-sub-headingis-style-sub-headingSection heading style, used as accordion title in mobile rendering
Sub Treetaxonomy-menu-link-sub-treeis-style-sub-treeExpandable sub-menu with nested child links, enableSubMenu: true
Sub Expandtaxonomy-menu-link-sub-expandis-style-sub-expandToggleable expand/collapse menu, enableSubMenu: true

Inner Blocks

Allowed blocks:

  • prc-block/taxonomy-list-link (self-referencing for nested menus)
  • core/paragraph
  • core/heading

Parent / Ancestor Requirements

ConstraintValue
parentprc-block/taxonomy-list

Context

DirectionKeyMaps to
Providesstylestyle attribute
UsestaxonomyTaxonomy slug from parent prc-block/taxonomy-list
UsesstyleStyle object from parent

Usage

Insert Taxonomy List Link blocks inside a prc-block/taxonomy-list. Choose a variation based on the desired behavior:

  • Link — standard navigation link to a term archive.
  • Sub Heading — visual section divider used as a label. On mobile accordion conversion, this label becomes the accordion title.
  • Sub Tree — hierarchical menu with nested child links, toggled via a chevron icon.
  • Sub Expand — expand/collapse section with a plus/minus toggle button.

Active state is tracked via the taxonomyLink URL query parameter. When a link is clicked, its term ID is added to or removed from the URL, and the corresponding menu item is highlighted.

Block Markup (save)

Standard inner blocks save. Server-side rendering augments the output with interactive directives and icons.

PHP Rendering

class-taxonomy-list-link.php (PRC\Platform\Blocks\Taxonomy_List_Link)

Query var registration:

  • Registers taxonomyLink as a public query variable via query_vars filter, enabling URL-based active state tracking.

Render callback:

  1. Builds the link template with appropriate icon: chevron for sub-trees, plus/minus for sub-expand menus (using PRC\Platform\Icons\render()).
  2. For sub-menu variations, adds a toggle button alongside the link.
  3. Sets data-wp-interactive="prc-block/taxonomy-list-link".
  4. Injects data-wp-context with { id, label, isActive, hasSubMenu, subExpandLabel }.
  5. isActive is determined by comparing the link's term ID against the current taxonomyLink query var value.
  6. Binds click handler: data-wp-on--click="actions.onClick".
  7. Binds dynamic class: data-wp-class--is-active="context.isActive".
  8. For sub-expand menus, binds the expand label text: data-wp-text="callbacks.getExpandedMenuLabel".

The view script module bundles @wordpress/url helpers; no separate wp-url script enqueue is required.

Frontend Interactivity

view.js registers the prc-block/taxonomy-list-link store.

Actions:

  • onClick — Toggles context.isActive. When activating, appends taxonomyLink={id} to the URL via addQueryArgs from @wordpress/url. When deactivating, removes the query arg via removeQueryArgs. Updates window.location to persist state.

Callbacks:

  • getExpandedMenuLabel — Returns "Less" when context.isActive is true, "More" otherwise. Used for the sub-expand toggle button label.
  • onInit — On page load, if the link is already active (from the URL query var), scrolls the link element into view via ref.scrollIntoView({ behavior: 'smooth' }) instead of getElementById, avoiding null reference errors when the DOM node is missing.
BlockRelationship
prc-block/taxonomy-listRequired parent container
prc-block/taxonomy-searchSibling block for term search within the same list
prc-block/taxonomy-index-list-controllerGrandparent controller managing desktop/mobile rendering

Was this helpful?