Access / Filter block variations in Gutenberg, in WordPress 5.6

This whole block variations thing is a complete red herring, a wild goose chase!

But lets just follow it to its conclusion before I share the actual solution, which is much simpler than you’d think.


You wouldn’t look at the variation itself, variations set different attributes, and it’s the attributes you should look for, not the variation.

For example, here’s is the twitter variation as defined in packages/block-library/src/embed/variations.js:

    {
        name: 'twitter',
        title: 'Twitter',
        icon: embedTwitterIcon,
        keywords: [ 'tweet', __( 'social' ) ],
        description: __( 'Embed a tweet.' ),
        patterns: [ /^https?:\/\/(www\.)?twitter\.com\/.+/i ],
        attributes: { providerNameSlug: 'twitter', responsive: true },
    },

Instead of looking at the block variation, check the providerNameSlug attribute instead.

But This is All Barking Up The Wrong Tree

This is not how you would do this at all, in fact your problem is completely unrelated to blocks and the editor!

If you want to modify OEmbed URLs, don’t modify the blocks that render OEmbeds, modify the OEmbed! WordPress has had filters for this for years, long before the block editor was introduced.

Thankfully, someone asked how to do this in 2011, and the answer should still work:

https://wordpress.stackexchange.com/a/14438/736