12

Following up on this question, I want to remove some of the default (core) embed blocks in the WordPress block editor. As of WordPress 5.6, the blocks are no longer available under the core-embed/* namespace.

How can I unregister individual core embed blocks?

2 Answers 2

18

With WordPress 5.6 (Gutenberg v8.8.0), the implementation of the core-embed/* blocks changed (see pull request #24090: Refactor embed block to single block with block variations). There are now 43 blocks with block variations of the core/embed block.

Available core blocks are:

core/paragraph
core/image
core/heading
core/gallery
core/list
core/quote
core/shortcode
core/archives
core/audio
core/button
core/buttons
core/calendar
core/categories
core/code
core/columns
core/column
core/cover
core/embed
core/file
core/group
core/freeform
core/html
core/media-text
core/latest-comments
core/latest-posts
core/missing
core/more
core/nextpage
core/preformatted
core/pullquote
core/rss
core/search
core/separator
core/block
core/social-links
core/social-link
core/spacer
core/subhead
core/table
core/tag-cloud
core/text-columns
core/verse
core/video

Unregister embeds altogether (including variations):

wp.domReady(function () {
  wp.blocks.unregisterBlockType('core/embed');
});

The blocks previously listed as core-embed/* are now available as a variation of core/embed:

console.table(wp.blocks.getBlockVariations('core/embed'));

Available block variations of core/embed are:

amazon-kindle
animoto
bluesky
cloudup
collegehumor
crowdsignal
dailymotion
facebook
flickr
imgur
instagram
issuu
kickstarter
meetup-com
mixcloud
pinterest
pocket-casts
reddit
reverbnation
screencast
scribd
slideshare
smugmug
soundcloud
speaker-deck
spotify
ted
tiktok
tumblr
twitter
videopress
vimeo
wolfram-cloud
wordpress
wordpress-tv
youtube

You can unregister a single variation like this:

wp.domReady(function () {
  wp.blocks.unregisterBlockVariation('core/embed', 'twitter');
});

Or unregister all variations and only allow individual variations:

wp.domReady(function () {
  const allowedEmbedBlocks = [
    'vimeo',
    'youtube',
  ];
  wp.blocks.getBlockVariations('core/embed').forEach(function (blockVariation) {
    if (-1 === allowedEmbedBlocks.indexOf(blockVariation.name)) {
      wp.blocks.unregisterBlockVariation('core/embed', blockVariation.name);
    }
  });
});
4
  • 1
    Do you have to unregister each variation individually or can you just unregister the block itself? And instead of hardcoding, why not use the result from wp.blocks.getBlockVariations('core/embed')?
    – kero
    Commented Dec 10, 2020 at 10:07
  • 2
    @kero Removing the embed block also removes all the variations (see updated answer above). It might be useful to keep the embed block and just remove individual variations. Maybe I want to embed videos (from YouTube and Vimeo) but get rid of all the other embeds.
    – Sven
    Commented Dec 10, 2020 at 10:22
  • So there is no longer any way to remove a particular embed block using PHP only the whole set? Commented Jun 8, 2023 at 15:04
  • 1
    'pocketcasts' should be 'pocket-casts' (tested in WP 6.4) in the list of core/embed variations
    – Erwan
    Commented Jul 1 at 7:44
10

As a theme developer I often want the embed blocks restricted to youtube and vimeo, just as Sven. So, following Sven's answer: In my php code:

function my_theme_deny_list_blocks() {
    wp_enqueue_script(
        'deny-list-blocks',
        get_template_directory_uri() . '/assets/js/deny-list-blocks.js',
        array( 'wp-blocks', 'wp-dom-ready', 'wp-edit-post' )
    );
}
add_action( 'enqueue_block_editor_assets', 'my_theme_deny_list_blocks' );

In my new javascript file deny-list-blocks.js:

wp.domReady( function() {

    var embed_variations = [
                            'amazon-kindle',
                            'animoto',
                            'cloudup',
                            'collegehumor',
                            'crowdsignal',
                            'dailymotion',
                            'facebook',
                            'flickr',
                            'imgur',
                            'instagram',
                            'issuu',
                            'kickstarter',
                            'meetup-com',
                            'mixcloud',
                            'reddit',
                            'reverbnation',
                            'screencast',
                            'scribd',
                            'slideshare',
                            'smugmug',
                            'soundcloud',
                            'speaker-deck',
                            'spotify',
                            'ted',
                            'tiktok',
                            'tumblr',
                            'twitter',
                            'videopress',
                            //'vimeo'
                            'wordpress',
                            'wordpress-tv',
                            //'youtube'
                ];

    for (var i = embed_variations.length - 1; i >= 0; i--) {
        wp.blocks.unregisterBlockVariation('core/embed', embed_variations[i]);
    }
} );

Notice that vimeo and youtube are commented. Nevertheless, it should be a better way to do this, for instance disabling all variations in one line, then enabling only the desired ones.

Also worth noticing that all themes using the allowed_block_types filter to disable embeds will have to be modified when updating wordpress to 5.6.

7
  • Thank you! For me, the working solution was a combination of your answer and @Sven's answer: I took the PHP part from your answer (in functions.php) and used the very last JS code block from Sven's answer as the separate deny-list-blocks.js file which your PHP function links to.
    – Johannes
    Commented Mar 3, 2021 at 22:20
  • @Marc what would it be a suitable alternative to allowed_block_types filter?
    – Giorgio25b
    Commented Mar 6, 2021 at 0:21
  • 1
    @Johannes is there a link to your solution?
    – Giorgio25b
    Commented Mar 6, 2021 at 0:24
  • @Giorgio25b Well, there are two public websites where I applied that solution, but as long as you don't have a user account for these (which won't be possible), you wouldn't be able to check any of that code or see which blocks are available for users.
    – Johannes
    Commented Mar 6, 2021 at 0:30
  • 1
    @Johannes no, I meant is there a shared snippet, a gist, a POW, something to see your implemented code without having to share details of any of your production projects ;-)
    – Giorgio25b
    Commented Mar 7, 2021 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.