You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何禁用Gutenberg自定义区块中的“Transform to”选项

Gutenberg自定义区块禁用Transform to选项方案

Gutenberg自定义区块的「Transform to」转换选项完全可以禁用,以下是两种可行实现方案:

方法1:注册区块时直接配置(推荐)

在调用registerBlockType注册自定义区块时,主动设置transforms配置项即可:

registerBlockType('your-plugin/your-custom-block', {
    // 其他原有配置项
    supports: {
        // 你已有的禁用可复用区块配置
        reusable: false,
    },
    transforms: {
        // 禁用当前区块转换到其他区块的选项
        to: [],
        // 若同时需要禁止其他区块转换为当前自定义区块,可将from也设为空数组
        from: [],
    },
    // 其他原有配置项
})

该方案无需额外添加钩子,性能最优,适合单个或少量自定义区块的配置场景。

方法2:全局过滤转换规则(适合批量处理)

如果需要统一禁用多个自定义区块的转换选项,可通过blocks.getBlockTransforms过滤器实现:

wp.hooks.addFilter(
    'blocks.getBlockTransforms',
    'your-plugin/disable-custom-block-transforms',
    ( transforms, direction, blockName ) => {
        // 替换为你需要禁用转换功能的自定义区块名称列表
        const disabledBlockList = [ 'your-plugin/block1', 'your-plugin/block2' ];
        if ( disabledBlockList.includes( blockName ) ) {
            return [];
        }
        return transforms;
    }
);

该方案可以覆盖所有第三方插件、主题额外注入的转换规则,适合多区块统一管控的场景。

注意事项

如果完成配置后仍出现转换选项,可优先检查是否有其他扩展额外注入了针对你的自定义区块的转换规则,使用第二种全局过滤方案即可彻底屏蔽这类额外规则。

内容的提问来源于stack exchange,提问作者kanlukasz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.07 01:15:03