3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WordPress5.6でembedブロックをフィルタリングする

Last updated at Posted at 2021-01-06

案件ではGutenbergの不要なブロックをdisabledにすることが多いと思うが、embedはWordPress5.6からallowed_block_typesのhookでcore-embed/youtubeのようにフィルタリングがかけられなくなってしまった。
が、enqueue_block_editor_assetsのhookで下記のjsを読ませればフィルタリングできる。

wp.domReady(() => {
    //デフォルトのバリエーションをチェックするとき
    //console.log(wp.blocks.getBlockVariations('core/embed'));

    //ホワイトリスト
    const allowedEmbedVariation = [
        'youtube',
        'vimeo'
    ];
    wp.blocks.getBlockVariations('core/embed').forEach((valiation) => {
        if (allowedEmbedVariation.indexOf(valiation.name) !== -1) return;
        wp.blocks.unregisterBlockVariation('core/embed', valiation.name);
    });
});
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?