I’m trying to re-categorise some existing blocks (both core and third party). I’ve been told this should be doable using the registerBlockType filter but I haven’t had much luck.
Could someone share a working example?
TIA
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Try this, it changes the core Spacer block from the Design to the Media category in the insertor:
function myprefixFilterSpacerCategory(settings, name) {
if (name === "core/spacer") {
// Object.assign can also be used instead of lodash.assign
return lodash.assign({}, settings, {
category: "media",
});
}
return settings;
}
wp.hooks.addFilter(
"blocks.registerBlockType",
"myprefix/filter-spacer-category",
myprefixFilterSpacerCategory
);
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0