render_block_core_term_description()


WordPressのrender_block_core_term_description()関数は、ターム(カテゴリーやタグなど)の説明文を表示するためのブロックをレンダリングするために使用されます。この関数は、ブロックエディター内でタームの説明文を表示する際に役立ちます。

構文

render_block_core_term_description( array $attributes );

引数の説明:

  • $attributes(array) — ブロックの属性を指定する配列。以下のキーを含むことができます:
    • termId(int) — 説明文を表示するタームのID。
    • textAlign(string) — テキストの配置(left, center, rightなど)。

例1: 基本的なターム説明文の表示

この例では、指定されたタームの説明文を表示します。

<?php echo render_block_core_term_description( array( 'termId' => get_queried_object_id() ) ); ?>

例2: テキストの中央揃え

タームの説明文を中央揃えで表示します。

<?php echo render_block_core_term_description( array( 'termId' => get_queried_object_id(), 'textAlign' => 'center' ) ); ?>

例3: 特定のタームIDを使用

特定のタームIDを指定して説明文を表示します。

<?php echo render_block_core_term_description( array( 'termId' => 5 ) ); ?>

例4: テキストの右揃え

タームの説明文を右揃えで表示します。

<?php echo render_block_core_term_description( array( 'termId' => get_queried_object_id(), 'textAlign' => 'right' ) ); ?>

例5: カスタムクラスの追加

ブロックにカスタムクラスを追加してスタイルを適用します。

<?php echo render_block_core_term_description( array( 'termId' => get_queried_object_id(), 'className' => 'custom-class' ) ); ?>

例6: ターム説明文のプレーンテキスト表示

タームの説明文をプレーンテキストとして表示します。

<?php echo wp_strip_all_tags( render_block_core_term_description( array( 'termId' => get_queried_object_id() ) ) ); ?>

例7: ターム説明文のHTMLタグを保持

タームの説明文をHTMLタグ付きで表示します。

<?php echo render_block_core_term_description( array( 'termId' => get_queried_object_id() ) ); ?>

注意点

  • タームIDが存在しない場合、関数は何も返しません。
  • textAlign属性は、CSSクラスとして適用されます。
  • この関数は、ブロックエディター内での使用を前提としています。

関連機能: