@伯吉尔的回答很好。https://wordpress.stackexchange.com/a/326969/198298
但可能缺少一些信息。
正如@birgire猜测的那样,确实有必要将代码包装在
wp.domReady( function() {
// ...
} );
即使脚本加载了依赖项
array( \'wp-blocks\', \'wp-dom-ready\', \'wp-edit-post\' )
就像在
block filters guide.
说到加载:如果你不是插件开发人员(像我一样),但只想为你(公司)博客的用户删除一些块类型,那么你应该在你的子主题中为此加载js文件functions.php
就像这样:
/** Allow js-side adjustments to block editor (aka Gutenberg), i.e. remove certain block types. */
function my_childtheme_enqueue_block_editor_adj() {
wp_enqueue_script(
\'block-editor-adjustments\',
get_stylesheet_directory_uri() . \'/js/block-editor-adjustments.js\',
array( \'wp-blocks\', \'wp-dom-ready\', \'wp-edit-post\' ),
);
}
add_action( \'enqueue_block_editor_assets\', \'my_childtheme_enqueue_block_editor_adj\' );
我的js文件如下所示:
wp.domReady(function () {
/**
* Remove some blocks from the block editor.
* This is not possible in php unfortunately.
*/
wp.blocks.unregisterBlockType(\'core/embed\');
var allowedEmbedBlocks = [
\'core-embed/twitter\',
\'core-embed/youtube\',
\'core-embed/facebook\',
\'core-embed/instagram\',
\'core-embed/wordpress\',
\'core-embed/flickr\',
\'core-embed/vimeo\',
];
wp.blocks.getBlockTypes().forEach(function (blockType) {
if (blockType.name.startsWith(\'core-embed\')
&& allowedEmbedBlocks.indexOf(blockType.name) === -1
) {
wp.blocks.unregisterBlockType(blockType.name);
}
});
});
这样,我现在可以专注于中的嵌入选项
allowedEmbedBlocks
关于Usercentrics数据隐私设置。