register_block_core_comments_title()


WordPressのregister_block_core_comments_title()関数は、コメントタイトルブロックを登録するために使用されます。この関数は、ブロックエディター内でコメントセクションのタイトルを表示するためのブロックを提供します。

構文

register_block_core_comments_title( array $args );

引数の説明:

  • $args(array) — ブロックの設定を定義するための配列。以下のキーを含むことができます:
    • 'api_version'(int) — ブロックAPIのバージョン。
    • 'title'(string) — ブロックのタイトル。
    • 'category'(string) — ブロックが属するカテゴリー。
    • 'icon'(string) — ブロックのアイコン。
    • 'attributes'(array) — ブロックの属性。

例1: 基本的なコメントタイトルブロックの登録

この例では、シンプルなコメントタイトルブロックを登録します。

register_block_core_comments_title( array( 'title' => 'コメントタイトル', 'category' => 'widgets', 'icon' => 'admin-comments' ) );

例2: カスタム属性を持つコメントタイトルブロック

カスタム属性を追加して、コメントタイトルブロックを登録します。

register_block_core_comments_title( array( 'title' => 'カスタムコメントタイトル', 'attributes' => array( 'customText' => array( 'type' => 'string', 'default' => 'デフォルトテキスト' ) ) ) );

例3: ブロックAPIバージョンの指定

ブロックAPIのバージョンを指定して、コメントタイトルブロックを登録します。

register_block_core_comments_title( array( 'api_version' => 2, 'title' => 'APIバージョン指定' ) );

例4: カスタムアイコンの使用

カスタムアイコンを使用して、コメントタイトルブロックを登録します。

register_block_core_comments_title( array( 'title' => 'カスタムアイコン', 'icon' => 'smiley' ) );

例5: カテゴリーの変更

ブロックのカテゴリーを変更して、コメントタイトルブロックを登録します。

register_block_core_comments_title( array( 'title' => 'カテゴリー変更', 'category' => 'embed' ) );

例6: デフォルト属性の設定

デフォルトの属性を設定して、コメントタイトルブロックを登録します。

register_block_core_comments_title( array( 'title' => 'デフォルト属性', 'attributes' => array( 'defaultText' => array( 'type' => 'string', 'default' => 'こんにちは' ) ) ) );

例7: 複数の属性を持つブロック

複数の属性を持つコメントタイトルブロックを登録します。

register_block_core_comments_title( array( 'title' => '複数属性', 'attributes' => array( 'textOne' => array( 'type' => 'string', 'default' => 'テキスト1' ), 'textTwo' => array( 'type' => 'string', 'default' => 'テキスト2' ) ) ) );

注意点

  • この関数は、ブロックエディターが有効な場合にのみ動作します。
  • ブロックの属性を定義する際は、適切なデフォルト値を設定することが推奨されます。
  • ブロックのカテゴリーやアイコンは、WordPressの既存のものを使用することができます。

関連機能: