register_block_core_image()


WordPressのregister_block_core_image()関数は、コアの画像ブロックを登録するために使用されます。この関数は、ブロックエディタで画像ブロックを利用可能にするために必要です。

構文

register_block_core_image( array $args );

引数の説明:

  • $args(array) — ブロックの設定を含む配列。以下のキーを持つことができます:
    • 'name'(string) — ブロックの名前。
    • 'title'(string) — ブロックのタイトル。
    • 'icon'(string) — ブロックのアイコン。
    • 'category'(string) — ブロックのカテゴリー。
    • 'render_callback'(callable) — ブロックのレンダリングコールバック。

例1: 基本的な画像ブロックの登録

この例では、基本的な画像ブロックを登録します。

register_block_core_image( array( 'name' => 'core/image', 'title' => '画像', 'icon' => 'format-image', 'category' => 'common', 'render_callback' => 'render_block_core_image' ) );

例2: カスタムアイコンを使用した画像ブロックの登録

カスタムアイコンを使用して画像ブロックを登録します。

register_block_core_image( array( 'name' => 'core/image', 'title' => 'カスタム画像', 'icon' => 'smiley', 'category' => 'common', 'render_callback' => 'render_block_core_image' ) );

例3: カスタムカテゴリーでの画像ブロックの登録

カスタムカテゴリーに画像ブロックを登録します。

register_block_core_image( array( 'name' => 'core/image', 'title' => 'カスタムカテゴリー画像', 'icon' => 'format-image', 'category' => 'custom-category', 'render_callback' => 'render_block_core_image' ) );

例4: カスタムレンダリングコールバックを使用した画像ブロックの登録

カスタムレンダリングコールバックを使用して画像ブロックを登録します。

register_block_core_image( array( 'name' => 'core/image', 'title' => 'カスタムレンダリング画像', 'icon' => 'format-image', 'category' => 'common', 'render_callback' => 'custom_render_image_block' ) );

例5: 複数の引数を使用した画像ブロックの登録

複数の引数を使用して画像ブロックを登録します。

register_block_core_image( array( 'name' => 'core/image', 'title' => '複数引数画像', 'icon' => 'format-image', 'category' => 'common', 'render_callback' => 'render_block_core_image', 'attributes' => array( 'url' => array( 'type' => 'string' ) ) ) );

例6: 属性を指定した画像ブロックの登録

属性を指定して画像ブロックを登録します。

register_block_core_image( array( 'name' => 'core/image', 'title' => '属性付き画像', 'icon' => 'format-image', 'category' => 'common', 'render_callback' => 'render_block_core_image', 'attributes' => array( 'alt' => array( 'type' => 'string' ) ) );

例7: カスタムブロック名を使用した画像ブロックの登録

カスタムブロック名を使用して画像ブロックを登録します。

register_block_core_image( array( 'name' => 'custom/image', 'title' => 'カスタム名画像', 'icon' => 'format-image', 'category' => 'common', 'render_callback' => 'render_block_core_image' ) );

注意点

  • この関数は、WordPressのブロックエディタでのみ使用されます。
  • カスタムレンダリングコールバックを使用する場合、適切なHTMLを返すように注意してください。
  • ブロックの属性を定義する際は、適切な型を指定してください。

関連機能: