Skip to content

LinkControl: Allow filtering custom post type icons in search results#77748

Open
sarthaknagoshe2002 wants to merge 2 commits into
WordPress:trunkfrom
sarthaknagoshe2002:fix/issue-71491
Open

LinkControl: Allow filtering custom post type icons in search results#77748
sarthaknagoshe2002 wants to merge 2 commits into
WordPress:trunkfrom
sarthaknagoshe2002:fix/issue-71491

Conversation

@sarthaknagoshe2002

Copy link
Copy Markdown
Contributor

What?

Closes #71491

Adds a JavaScript filter blockEditor.linkControl.searchItemIcon to the <SearchItemIcon /> component to allow customizing the icon displayed in Link Control search suggestions.

Why?

Currently, custom post types cannot display their registered icons within the Link Control search results. This PR solves this by exposing a filter, allowing developers to inject custom SVG icons for specific custom post types or suggestion types (custom tax).

How?

Wraps the resolved icon variable in the SearchItemIcon component with applyFilters. This passes the default icon and the suggestion.type (post type) to the filter before rendering the final @wordpress/icons component.

Testing Instructions

  1. Enqueue a custom script in the editor, or open your browser console in the Block Editor.
  2. Add a filter to replace an icon for a specific post type (e.g., overriding pages or targeting a CPT):
import { verse } from '@wordpress/icons';
import { addFilter } from '@wordpress/hooks';

addFilter(
	'blockEditor.linkControl.searchItemIcon',
	'test-plugin',
	( icon, suggestionType ) => {
		if ( suggestionType === 'rt-movie' ) {
			return verse;
		}
		return icon;
	}
);
  1. Insert a Paragraph block and type some text.
  2. Highlight the text and press Cmd/Ctrl + K to open the Link Control.
  3. Search for the targeted post type.
  4. Verify that your custom icon appears next to the search result.

Screenshots or screencast

Before After
image image

@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Apr 28, 2026
@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: sarthaknagoshe2002 <sarthaknagoshe2002@git.wordpress.org>
Co-authored-by: dannyreaktiv <dannyreaktiv@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] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) labels Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) [Package] Block editor /packages/block-editor [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow custom icon in <SearchItemIcon/>

2 participants