문제

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top