Changing the category for existing Gutenberg blocks
-
19-05-2021 - |
質問
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
解決
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
);
所属していません wordpress.stackexchange