You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Navigation: allow plugins to register icons for custom post type and taxonomy variants #31226
Navigation inner blocks are automatically available for Custom Post Types and taxonomies. That was introduced in #29095 and works great, making plugin authors life much easier. However, it doesn't allow setting a custom icon for those inner blocks.
In the screenshot below, you can see the Product Link, Product Category Link and Product Tag Link blocks added by WooCommerce using the generic icon:
I anticipate this will be an issue for sites with several plugins installed.
@gwwar do you have any thoughts about whether an interface could be added so plugins can register custom icons for the Navigation inner blocks which are generated automatically?
@Aljullu I agree we should enable the ability to register custom icons for the core/navigation-link variations (which is what you are referring to as the innerBlocks.
You will also notice that once you insert one of the block variations for a custom post type the name of the block in the block sidebar still reads Post link. That should also be fixed.
I'm currently working on #31004 which standardizes the serialization of blocks to nav menu items (and vica versa) so that existing menus will translate perfectly over to the new Nav editor screen. I'd love some more 👀 on that if possible.
@gwwar do you have any thoughts about whether an interface could be added so plugins can register custom icons for the Navigation inner blocks which are generated automatically?
Yes, I hope we'll have this in the future. The current variations API only allows icons to be set with a JS function. We need to explore if we can set icons as a react component function OR svg string (and still have this work for React Native). Once an icon is serializable, it'll be possible then to update the server API.
The workaround for right now is adding a block filter, which even the core/navigation-link needs to do:
addFilter('blocks.registerBlockType','core/navigation-link',(settings,name)=>{if(settings.variations){constvariations=settings.variations.map((variation)=>{return{
...variation,
...(!variation.icon&&{icon: getIcon(variation.name),//add your custom icon here}),};});return{
...settings,
variations,};}returnsettings;);
You will also notice that once you insert one of the block variations for a custom post type the name of the block in the block sidebar still reads Post link.
To fix that, when registering the custom post type, add two new labels item_link and item_link_description. New post type labels were added to avoid joining two translated strings.
@Aljullu I agree we should enable the ability to register custom icons for the core/navigation-link variations (which is what you are referring to as the innerBlocks.
Thanks for clarifying those concepts to me, I'm still new to all the Gutenberg nomenclature. 🙂
I'm currently working on #31004 which standardizes the serialization of blocks to nav menu items (and vica versa) so that existing menus will translate perfectly over to the new Nav editor screen. I'd love some more 👀 on that if possible.
Will do. Adding this to my todo list for this week. 👍
The workaround for right now is adding a block filter, which even the core/navigation-link needs to do:
That worked great, thanks for pointing me in the right direction! I needed to tweak the code a bit because when calling it from a plugin, variation.icon is already set. Sharing the code here in case it's helpful for other plugin authors:
Hey @getdave - just triaging older issues - and wanted to see if we had inadvertently solved this one in the last 2 years? Or if it still needs working on.
Thanks for opening this, @Aljullu! As discussed above, plugins can set icons for their generated Navigation Link variations with a blocks.registerBlockType filter (see the example in this thread), and the block keeps any icon a variation already has. Server-generated variations can also be adjusted with the get_block_type_variations filter, which accepts a Dashicon name as the icon. Since that covered the original need, I'm closing this.
Activity
getdave commentedon Apr 27, 2021
@Aljullu I agree we should enable the ability to register custom icons for the
core/navigation-linkvariations (which is what you are referring to as theinnerBlocks.You will also notice that once you insert one of the block variations for a custom post type the name of the block in the block sidebar still reads
Post link. That should also be fixed.I'm currently working on #31004 which standardizes the serialization of blocks to nav menu items (and vica versa) so that existing menus will translate perfectly over to the new Nav editor screen. I'd love some more 👀 on that if possible.
gwwar commentedon Apr 27, 2021
Yes, I hope we'll have this in the future. The current variations API only allows icons to be set with a JS function. We need to explore if we can set icons as a react component function OR svg string (and still have this work for React Native). Once an icon is serializable, it'll be possible then to update the server API.
The workaround for right now is adding a block filter, which even the core/navigation-link needs to do:
gwwar commentedon Apr 27, 2021
To fix that, when registering the custom post type, add two new labels
item_linkanditem_link_description. New post type labels were added to avoid joining two translated strings.Aljullu commentedon Apr 28, 2021
@getdave
Thanks for clarifying those concepts to me, I'm still new to all the Gutenberg nomenclature. 🙂
Will do. Adding this to my todo list for this week. 👍
Aljullu commentedon Apr 28, 2021
@gwwar
That worked great, thanks for pointing me in the right direction! I needed to tweak the code a bit because when calling it from a plugin,
variation.iconis already set. Sharing the code here in case it's helpful for other plugin authors:jordesign commentedon Oct 26, 2023
Hey @getdave - just triaging older issues - and wanted to see if we had inadvertently solved this one in the last 2 years? Or if it still needs working on.
getdave commentedon Nov 7, 2023
I don't think this has been resolved no.
youknowriad commentedon Oct 18, 2026
Thanks for opening this, @Aljullu! As discussed above, plugins can set icons for their generated Navigation Link variations with a
blocks.registerBlockTypefilter (see the example in this thread), and the block keeps any icon a variation already has. Server-generated variations can also be adjusted with theget_block_type_variationsfilter, which accepts a Dashicon name as the icon. Since that covered the original need, I'm closing this.