【问题标题】:Filter the Gutenberg Block Editor controls过滤 Gutenberg 块编辑器控件
【发布时间】:2019-09-25 09:19:49
【问题描述】:

例如:在古腾堡“标题”块中,可以选择将级别设置为“H2、H3、H4”。 我如何(在哪里)限制这个列表?

例如,我只想允许“H3”

在互联网上到处找。 通过“registerBlockType”过滤似乎不是可行的方法。

【问题讨论】:

    标签: wordpress editor wordpress-gutenberg


    【解决方案1】:

    据我所知,没有用于这种过滤的 API。解决方法是使用display: none 隐藏面板或按钮。根据 Github Wordpress 5.4 上的this discussion 可能会解决这个问题。

    【讨论】:

      【解决方案2】:

      对于这个特定的事情似乎还没有一个很好的解决方案,但你基本上可以通过这样的方式达到预期的效果:

      add_action('admin_head', function() {
        echo '<style>
        #editor .block-library-heading-level-toolbar button:nth-child(1),
        #editor .block-library-heading-level-toolbar button:nth-child(4),
        #editor .block-library-heading-level-toolbar button:nth-child(5),
        #editor .block-library-heading-level-toolbar button:nth-child(6) {
          display: none;
        }
        </style>';
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-07-24
        • 2020-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-16
        • 1970-01-01
        • 2020-09-18
        相关资源
        最近更新 更多