Skip to content

Resolve SVG through Icon Registry - #82062

Open
Vrishabhsk wants to merge 3 commits into
WordPress:trunkfrom
Vrishabhsk:feature/resolve-svg-icon-registry
Open

Vrishabhsk wants to merge 3 commits into
WordPress:trunkfrom
Vrishabhsk:feature/resolve-svg-icon-registry

Conversation

@Vrishabhsk

Copy link
Copy Markdown
Contributor

What?

Why?

  • Themes that need to replace Core block UI icons (e.g. to match a custom icon font like Material Symbols) currently must hide the hardcoded SVGs via CSS hacks and recreate them with ::before pseudo-elements.
  • Some workarounds target SVG path data in CSS selectors, which break if Core updates an SVG.
  • The Icon Registry already exists as a theming seam, but Core block UI icons don't use it yet.

How?

Exposed icon identifiers for theme override:

Block UI element Icon ID
Search submit button core/search
Navigation submenu chevron core/navigation-submenu
Navigation responsive toggle (default) core/navigation-menu-toggle
Navigation responsive toggle (menu variant) core/menu
Navigation & Image lightbox close core/close
Image lightbox previous / next core/chevron-left / core/chevron-right

Key implementation details:

  1. Extended the SVG sanitizer to allow stroke, stroke-width, stroke-linecap, stroke-linejoin, and fill attributes — needed for the stroked submenu chevron.
  2. Registered core/navigation-submenu and core/navigation-menu-toggle via inline content in gutenberg_register_default_icons() since their SVGs don't fit the icon library's 24×24 / fill="currentColor" convention.
  3. Made core/close public in the icon manifest.
  4. Updated PHP render callbacks to call wp_get_icon() with fallback to the original hardcoded SVG.
  5. Updated editor JS components to use a new useIcon() hook that fetches icons from the registry via core-data, with fallback to the original React SVGs.

Theme override example:

add_action( 'init', function () {
    wp_unregister_icon( 'core/search' );
    wp_register_icon( 'core/search', array(
        'label'   => 'Search',
        'content' => '<svg viewBox="0 0 24 24"><path d="..." /></svg>',
    ) );
}, 20 );

Works in both editor and frontend.

Testing Instructions

  1. Add the snippet below to a theme's functions.php:
add_action( 'init', function () {
    wp_unregister_icon( 'core/search' );
    wp_register_icon( 'core/search', array(
        'label'   => 'Search',
        'content' => '<svg viewBox="0 0 24 24"><path d="M0 0 L24 24 M24 0 L0 24" stroke="currentColor" stroke-width="2"/></svg>',
    ) );
}, 20 );
  1. Add a Search block with "Use icon button" enabled → custom SVG appears on frontend and editor.
  2. Remove the override → default search icon is restored.
  3. Run automated tests: npm run wp-env-test run -- phpunit --filter Tests_Blocks_Render_Icons

Use of AI Tools

This PR was implemented with assistance from GLM-5.2 via Ollama (ollama/glm-5.2:cloud).

@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.

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

Co-authored-by: Vrishabhsk <vrishabhsk@git.wordpress.org>
Co-authored-by: Jiwoon-Kim <kimjiwoon@git.wordpress.org>

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

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Feature] Icons Related to Icon registration API and Icon REST API labels Aug 26, 2026
@t-hamano t-hamano changed the title Feature : Resolve SVG through Icon Registry Resolve SVG through Icon Registry Aug 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Icons Related to Icon registration API and Icon REST API [Package] Block library /packages/block-library [Package] Icons /packages/icons [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow Core blocks to resolve internal UI SVGs through the Icon Registry

2 participants