0

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

0

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
);

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.