Skip to content

Feat: Navigation Link – Add "Show child categories" toggle for taxonomy Category Links#77679

Open
priyanshuhaldar007 wants to merge 2 commits intoWordPress:trunkfrom
priyanshuhaldar007:feat/add-control-for-child-categories
Open

Feat: Navigation Link – Add "Show child categories" toggle for taxonomy Category Links#77679
priyanshuhaldar007 wants to merge 2 commits intoWordPress:trunkfrom
priyanshuhaldar007:feat/add-control-for-child-categories

Conversation

@priyanshuhaldar007
Copy link
Copy Markdown

What?

Closes https://core.trac.wordpress.org/ticket/64988

Adds a showChildCategories boolean attribute to the core/navigation-link block. When enabled on a Category Link block, child categories of the selected parent are automatically fetched and rendered as a nested submenu/dropdown in the frontend navigation.

Why?

The Navigation block's Category Link currently only links to a single category archive — it has no way to expose child categories as a submenu. This is inconsistent with the Page List block, which supports hierarchical parent–child page structures out of the box. Users with hierarchical taxonomies (blogs, WooCommerce stores, taxonomy-heavy sites) are forced to manually construct submenus or write custom code to replicate behavior that Page List provides natively.

How?

  • Added showChildCategories: { type: boolean, default: false } to block.json for core/navigation-link.
  • Added a ToggleControl in edit.js (block sidebar inspector) that toggles the new attribute. The control is only shown when the selected link kind is taxonomy.
  • Updated the PHP render callback (render_block_core_navigation_link) to call get_terms() with parent set to $attributes['id'] when showChildCategories is true and kind is taxonomy.
  • Child terms are rendered as <li> navigation items inside a wp-block-navigation__submenu-container, reusing the same Interactivity API markup pattern (data-wp-* attributes, submenu toggle button) as existing inner-block-based submenus.
  • The has-child / wp-block-navigation-submenu classes and submenu icon button are applied when either inner blocks or dynamic child terms are present, ensuring consistent hover/click/focus behaviour.

Testing Instructions

  1. Activate the Gutenberg plugin on a local WordPress install.
  2. Ensure at least one category exists with one or more child categories (e.g. parent: "News", children: "Sports", "Politics").
  3. Open a page or post and insert a Navigation block.
  4. Add a Category Link block inside the Navigation block and select the parent category (e.g. "News").
  5. In the block sidebar (Inspector Controls), confirm a "Show child categories" toggle is visible.
  6. Enable the toggle and save/update the post.
  7. View the page on the frontend — the parent category link should now display a dropdown submenu containing its child categories.
  8. Confirm hover, click, and keyboard navigation on the submenu work correctly.
  9. Disable the toggle, save, and confirm the submenu no longer appears on the frontend.
  10. Confirm that a Category Link block pointing to a non-taxonomy link (e.g. a page or custom URL) does not show the toggle.

Testing Instructions for Keyboard

  1. Tab to the parent category navigation item.
  2. Press Enter or Space to open the submenu.
  3. Tab through the child category links and confirm focus moves correctly.
  4. Press Escape to close the submenu and confirm focus returns to the parent item.

Implementation Screencast

Screen.Recording.2026-04-26.at.12.20.42.PM.mov

Use of AI Tools

Claude (Anthropic) was used to assist with drafting this PR description, and Gemini was used to assist with debugging.

@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @priyanshuhaldar007.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: priyanshuhaldar007.


To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Apr 26, 2026
@github-actions
Copy link
Copy Markdown

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @priyanshuhaldar007! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@github-actions github-actions Bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Apr 26, 2026
@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Block] Navigation Link Affects the Navigation Link Block labels Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Navigation Link Affects the Navigation Link Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants