admin管理员组

文章数量:1133652

I was trying to use this to create a Youtube video block using JavaScript:

// Define the YouTube video URL (replace with your desired URL)
const youtubeVideoURL = '';

// Create a new YouTube video block
const youtubeVideoBlock = wp.blocks.createBlock('core-embed', {
  url: youtubeVideoURL,
});

But I get the following error:

Uncaught Error: Block type 'core-embed' is not registered.

That this means it's actually impossible to programmatically create an "embed" block for Youtube videos?

It works fine for paragraphs, quotes, images... so I'm surprised this is not working for embeds.

I was trying to use this to create a Youtube video block using JavaScript:

// Define the YouTube video URL (replace with your desired URL)
const youtubeVideoURL = 'https://youtu.be/NNrj0N-yTnM';

// Create a new YouTube video block
const youtubeVideoBlock = wp.blocks.createBlock('core-embed', {
  url: youtubeVideoURL,
});

But I get the following error:

Uncaught Error: Block type 'core-embed' is not registered.

That this means it's actually impossible to programmatically create an "embed" block for Youtube videos?

It works fine for paragraphs, quotes, images... so I'm surprised this is not working for embeds.

Share Improve this question asked Oct 5, 2023 at 18:05 AlvaroAlvaro 1411 silver badge12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

Perhaps the name you're using is incorrect?

At least in /block-library/src/embed/core-embeds.js the different embed types seem to follow core-embed/{source} pattern on their names - e.g. core-embed/youtube. And the embed block itself has core/embed as its name.

本文标签: javascriptCreate Youtube embed block with createBlock