Title: ブロックの静的レンダリングと動的レンダリング
Author: Akira Tachibana
Published: 2024年1月27日
Last modified: 2026年8月11日

---

# ブロックの静的レンダリングと動的レンダリング

## この投稿内

 * [静的レンダリング](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/static-dynamic-rendering/?output_format=md#%e9%9d%99%e7%9a%84%e3%83%ac%e3%83%b3%e3%83%80%e3%83%aa%e3%83%b3%e3%82%b0)
    - [ブロックで静的レンダリングを定義する方法](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/static-dynamic-rendering/?output_format=md#%e3%83%96%e3%83%ad%e3%83%83%e3%82%af%e3%81%a7%e9%9d%99%e7%9a%84%e3%83%ac%e3%83%b3%e3%83%80%e3%83%aa%e3%83%b3%e3%82%b0%e3%82%92%e5%ae%9a%e7%be%a9%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95)
 * [動的レンダリング](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/static-dynamic-rendering/?output_format=md#%e5%8b%95%e7%9a%84%e3%83%ac%e3%83%b3%e3%83%80%e3%83%aa%e3%83%b3%e3%82%b0)
    - [ブロックで動的レンダリングを定義する方法](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/static-dynamic-rendering/?output_format=md#%e3%83%96%e3%83%ad%e3%83%83%e3%82%af%e3%81%a7%e5%8b%95%e7%9a%84%e3%83%ac%e3%83%b3%e3%83%80%e3%83%aa%e3%83%b3%e3%82%b0%e3%82%92%e5%ae%9a%e7%be%a9%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95)
    - [データベース内の動的ブロックの HTML 表現 (save)](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/static-dynamic-rendering/?output_format=md#%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e5%86%85%e3%81%ae%e5%8b%95%e7%9a%84%e3%83%96%e3%83%ad%e3%83%83%e3%82%af%e3%81%ae-html-%e8%a1%a8%e7%8f%be-save)
 * [その他の情報](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/static-dynamic-rendering/?output_format=md#%e3%81%9d%e3%81%ae%e4%bb%96%e3%81%ae%e6%83%85%e5%a0%b1)

ブロックのフロントエンドのマークアップ生成には2通りの方式があります。リクエストに
応じてサーバーサイドで動的に生成する方式 (動的ブロック、ダイナミックブロック)と、
ブロックエディターでの save プロセス中に静的に生成する方式 (静的ブロック) です。
この記事では、それぞれの方式について説明します。

> 投稿「[Static vs. dynamic blocks: What’s the difference?](https://developer.wordpress.org/news/2023/02/27/static-vs-dynamic-blocks-whats-the-difference/)」
> は、このトピックに関する素晴らしい入門記事です。

## 󠀁[静的レンダリング](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/static-dynamic-rendering/?output_format=md#%e9%9d%99%e7%9a%84%e3%83%ac%e3%83%b3%e3%83%80%e3%83%aa%e3%83%b3%e3%82%b0)󠁿

「静的レンダリング」を行うブロックは、保存時に、データベース内に保存され固定される
フロントエンド出力を生成します。このブロックは [HTML マークアップ](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/markup-representation-block/)
の定義に関して、 `save` 関数にのみ依存します。マークアップはブロックエディター内
で手動で編集しない限り、変更されません。

ブロックが動的なレンダリング方法を使用しなければ、すなわち、ページが読み込まれた
ときに PHP を介してその場でコンテンツを生成しなければ、このブロックは「静的ブロック」
と見なされます。

次の図は、静的ブロックのコンテンツがどのようにデータベース内に保存され、どのよう
にフロントエンドで HTML として取得、レンダーされるかを示しています。

![図: 静的レンダリングのブロック](https://developer.wordpress.org/files/2024/01/
static-rendering.png)

### 󠀁[ブロックで静的レンダリングを定義する方法](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/static-dynamic-rendering/?output_format=md#%e3%83%96%e3%83%ad%e3%83%83%e3%82%af%e3%81%a7%e9%9d%99%e7%9a%84%e3%83%ac%e3%83%b3%e3%83%80%e3%83%aa%e3%83%b3%e3%82%b0%e3%82%92%e5%ae%9a%e7%be%a9%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95)󠁿

`save` 関数は、[クライアントにブロックを登録する](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/registration-of-a-block/#registration-of-the-block-with-javascript-client-side)
際に定義され、ブロックの HTML 構造を指定します。HTML 構造はエディターでのブロック
の保存時にデータベース内に保存され、フロントエンドでのブロックの表示に使用されます。

WordPress のブロックは、固有の[ブロック区切り](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/markup-representation-block/)
として機能する特別なコメントタグ内にカプセル化されます。ただし、静的ブロックの `
save` 関数で定義された HTML のみがこれらの区切り文字を取り除いてレンダーされます。

#### 󠀁[整形済みテキストブロックの静的レンダリングの例](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/static-dynamic-rendering/?output_format=md#%e6%95%b4%e5%bd%a2%e6%b8%88%e3%81%bf%e3%83%86%e3%82%ad%e3%82%b9%e3%83%88%e3%83%96%e3%83%ad%e3%83%83%e3%82%af%e3%81%ae%e9%9d%99%e7%9a%84%e3%83%ac%e3%83%b3%e3%83%80%e3%83%aa%e3%83%b3%e3%82%b0%e3%81%ae)󠁿

コアの[整形済みテキスト](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/preformatted)
ブロックの [`save`](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/preformatted/save.js)
関数は以下のようになります。

    ```notranslate
    import { RichText, useBlockProps } from '@wordpress/block-editor';

    export default function save( { attributes } ) {
    	const { content } = attributes;

    	return (
    		<pre { ...useBlockProps.save() }>
    			<RichText.Content value={ content } />
    		</pre>
    	);
    }
    ```

この関数は、`attributes.content` の値が `"This is some preformatted text"` のとき、
次のようなブロックのマークアップ表現を生成します：

    ```notranslate
    <!-- wp:preformatted -->
    <pre class="wp-block-preformatted">This is some preformatted text</pre>
    <!-- /wp:preformatted -->
    ```

フロントエンドでこのブロックは、次のようなマークアップを返します。区切りがないことに
注意してください。

    ```notranslate
    <pre class="wp-block-preformatted">This is some preformatted text</pre>
    ```

次のセクションで説明する動的ブロックは、静的ブロックと同様に `save` 関数で、最初
の HTML 構造を指定できます。しかし、動的ブロックは主にサーバー側のレンダリングに
依存してコンテンツを生成します。何らかの理由で動的なレンダリングが利用できない場合、
たとえばブロックのプラグインが無効の場合など、システムはデータベースに保存された
HTML 構造を使用してフロントエンドにブロックを表示します。

この仕組みの実践的なデモについては、チュートリアルの[はじめてのブロック作成](https://ja.wordpress.org/team/handbook/block-editor/getting-started/tutorial/)
を参照してください。特に、[静的レンダリングの追加](https://ja.wordpress.org/team/handbook/block-editor/getting-started/tutorial/#adding-static-rendering)
セクションではブロックが、保存された HTML 構造と動的レンダリング機能の両方を持つ
方法を説明しています。

WordPress では [`render_block`](https://developer.wordpress.org/reference/functions/render_block/)
や [`render_callback`](https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/creating-dynamic-blocks/)
関数のようなメカニズムが提供され、フロントエンドに表示される前に保存されたブロック
の HTML を変更できます。これらのツールは、ブロックの出力を動的にカスタマイズする
機能を開発者に提供し、複雑でインタラクティブなユーザー体験に対応します。

静的レンダリングを使用する例、すなわち、出力が保存時に固定され、サーバーサイドで
の処理に依存しない WordPress ブロックの例には、他にも以下があります。

 * [区切り](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/separator/save.js)
 * [スペーサー](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/spacer/save.js)
 * [ボタン](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/button/save.js)

## 󠀁[動的レンダリング](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/static-dynamic-rendering/?output_format=md#%e5%8b%95%e7%9a%84%e3%83%ac%e3%83%b3%e3%83%80%e3%83%aa%e3%83%b3%e3%82%b0)󠁿

「動的レンダリング」を行うブロックは、フロントエンド側で要求された際に、リアルタイム
でコンテンツと構造を生成するように設計されています。データベースに保存された固定
した HTML 構造を持つ静的ブロックとは異なり、「動的ブロック」はサーバーサイドの処理
に依存して動的に出力を構築するため、汎用性が高く、頻繁に更新する必要があるコンテンツ
や外部データに依存するコンテンツに適しています。

次の図は、どのように動的ブロックの表現が保存され、フロントエンドで HTML として取得
され、動的にレンダーされるかを示しています。

![図: 動的レンダリングのブロック](https://developer.wordpress.org/files/2024/01/
dynamic-rendering.png)

動的ブロックの一般的な使用例を挙げます。

 1. **投稿が更新されていなくても、コンテンツが変更されるべきブロック：** このブロック
    の例は[最新の投稿](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/latest-posts)
    ブロックです。新しい投稿が公開されると自動的に更新されます。

 2. **マークアップの更新が即座にフロントエンドに表示されるべきブロック:** 新しいクラス
    や HTML 要素の追加、その他の方法によるレイアウトの変更などでブロックの構造を変更
    する場合、動的ブロックを使用すると、サイト全体でのブロックの利用箇所のすべてで即座
    に変更を適用できます。動的ブロックでなければ、同様の更新はブロックエディター内で
    [バリデーションエラー](https://ja.wordpress.org/team/handbook/block-editor/reference-guides/block-api/block-edit-save/#validation)
    を引き起こします。

### 󠀁[ブロックで動的レンダリングを定義する方法](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/static-dynamic-rendering/?output_format=md#%e3%83%96%e3%83%ad%e3%83%83%e3%82%af%e3%81%a7%e5%8b%95%e7%9a%84%e3%83%ac%e3%83%b3%e3%83%80%e3%83%aa%e3%83%b3%e3%82%b0%e3%82%92%e5%ae%9a%e7%be%a9%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95)󠁿

ブロックは主に2つの方法で動的レンダリングを定義できます。

 1. [`register_block_type()`](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/registration-of-a-block/#registration-of-the-block-with-php-server-side)
    関数に渡す `render_callback` 引数を使用する。これは [PHP のみのブロック](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/registration-of-a-block/#php-%e3%81%ae%e3%81%bf%e3%81%ae%e3%83%96%e3%83%ad%e3%83%83%e3%82%af%e3%81%a8%e8%87%aa%e5%8b%95%e7%99%bb%e9%8c%b2)
    で必要とされます。

 2. 通常 `render.php` という名前の個別の PHP ファイルを使用する。このファイルのパス
    は `block.json` ファイルの [`render`](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/block-json/#files-for-the-blocks-behavior-output-or-style)
    プロパティを使用して定義します。

どちらの方法も次のデータを受け取ります。

 * `$attributes`: ブロックの属性の配列
 * `$content`: データベース内に保存される、ブロックのマークアップ (もしあれば)
 * `$block`: [WP_Block](https://developer.wordpress.org/reference/classes/wp_block/)
   クラスのインスタンス。レンダーされるブロックを表す ([ブロックのメタデータ](https://ja.wordpress.org/team/handbook/block-editor/reference-guides/block-api/block-metadata/))。

#### 󠀁[サイトのタイトルブロックの動的レンダリングの例](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/static-dynamic-rendering/?output_format=md#%e3%82%b5%e3%82%a4%e3%83%88%e3%81%ae%e3%82%bf%e3%82%a4%e3%83%88%e3%83%ab%e3%83%96%e3%83%ad%e3%83%83%e3%82%af%e3%81%ae%e5%8b%95%e7%9a%84%e3%83%ac%e3%83%b3%e3%83%80%e3%83%aa%e3%83%b3%e3%82%b0%e3%81%ae)󠁿

[サイトのタイトル](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/site-title)
ブロックは以下の[`render_callback`](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/site-title/index.php)
を使用します。

    ```notranslate
    function render_block_core_site_title( $attributes ) {
    	$site_title = get_bloginfo( 'name' );
    	if ( ! $site_title ) {
    		return;
    	}

    	$tag_name = 'h1';
    	$classes  = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
    	if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
    		$classes .= ' has-link-color';
    	}

    	if ( isset( $attributes['level'] ) ) {
    		$tag_name = 0 === $attributes['level'] ? 'p' : 'h' . (int) $attributes['level'];
    	}

    	if ( $attributes['isLink'] ) {
    		$aria_current = is_home() || ( is_front_page() && 'page' === get_option( 'show_on_front' ) ) ? ' aria-current="page"' : '';
    		$link_target  = ! empty( $attributes['linkTarget'] ) ? $attributes['linkTarget'] : '_self';

    		$site_title = sprintf(
    			'<a href="%1$s" target="%2$s" rel="home"%3$s>%4$s</a>',
    			esc_url( home_url() ),
    			esc_attr( $link_target ),
    			$aria_current,
    			esc_html( $site_title )
    		);
    	}
    	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => trim( $classes ) ) );

    	return sprintf(
    		'<%1$s %2$s>%3$s</%1$s>',
    		$tag_name,
    		$wrapper_attributes,
    		// already pre-escaped if it is a link.
    		$attributes['isLink'] ? $site_title : esc_html( $site_title )
    	);
    }
    ```

しかし、[`index.js`](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/site-title/index.js)
ファイルを見ればわかるように、このブロックには `save` 関数が定義されていません。
したがってデータベース内のブロックのマークアップ表現は次のようになります。

    ```notranslate
    <!-- wp:site-title /-->
    ```

フロントエンドでは、`render_callback`を使用して、ブロックがリクエストされた時点で
のサーバ上の特定の値に応じて、ブロックのマークアップが動的にレンダーされます。値
には、現在のサイトのタイトル、URL、リンク先などが含まれます。

    ```notranslate
    <h1 class="wp-block-site-title"><a href="https://www.wp.org" target="_self" rel="home">My WordPress Website</a></h1>
    ```

### 󠀁[データベース内の動的ブロックの HTML 表現 (save)](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/static-dynamic-rendering/?output_format=md#%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e5%86%85%e3%81%ae%e5%8b%95%e7%9a%84%e3%83%96%e3%83%ad%e3%83%83%e3%82%af%e3%81%ae-html-%e8%a1%a8%e7%8f%be-save)󠁿

動的ブロックの `save`コールバック関数は `null`のみを返して、エディターに対し、既存
の[ブロック属性](https://ja.wordpress.org/team/handbook/block-editor/reference-guides/block-api/block-attributes/)
と一緒にブロックの区切りコメントだけをデータベースに保存するように指示できます。
これらの属性はサーバーサイドのレンダリングコールバックに渡され、サイトのフロント
エンドでどのようにブロックを表示するかを決定します。

`save` が `null` の場合、ブロックエディターは [ブロックマークアップの検証プロセス](https://ja.wordpress.org/team/handbook/block-editor/reference-guides/block-api/block-edit-save/#validation)
をスキップし、頻繁なマークアップの変更で引き起こされる問題を回避します。

動的レンダリングを持つブロックはまた、ブロックの HTML 表現をバックアップとして保存
できます。サーバサイドレンダリングのコールバックを提供した場合、データベース内の
ブロックを表す HTML はコールバックの出力に置き換えられますが、ブロックを登録した
プラグインをアンインストールするなどしてブロックが無効化されたり、レンダーコール
バックが削除されると、HTML はレンダーされます。

場合によってはブロックはブロックの HTML 表現を保存し、いくつかの条件が満たされた
場合にこのマークアップを微調整するために、動的レンダリングを使用します。この方法
を使用したコアブロックの例をいくつか挙げます。

 * [カバー](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/cover)
   ブロックは、データベース内にブロックの完全な HTML 表現を[保存](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/cover/save.js)
   します。このマークアップは [`render_callback`](https://github.com/WordPress/gutenberg/blob/22741661998834e69db74ad863705ee2ce97b446/packages/block-library/src/cover/index.php#L74)
   を介して処理され、「アイキャッチ画像を使用する」設定が有効な場合には、アイキャッチ
   画像が[動的に挿入](https://github.com/WordPress/gutenberg/blob/22741661998834e69db74ad863705ee2ce97b446/packages/block-library/src/cover/index.php#L16)
   されます。

 * [画像](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/image)
   ブロックもまたその HTML 表現をデータベース内に[保存](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/image/save.js)
   します。このマークアップは [`render_callback`](https://github.com/WordPress/gutenberg/blob/22741661998834e69db74ad863705ee2ce97b446/packages/block-library/src/image/index.php#L363)
   を介して処理され、特定の条件を満たす場合は、マークアップに[属性を追加](https://github.com/WordPress/gutenberg/blob/22741661998834e69db74ad863705ee2ce97b446/packages/block-library/src/image/index.php#L18)
   します。

動的ブロック内で [InnerBlocks](https://ja.wordpress.org/team/handbook/block-editor/how-to-guides/block-tutorial/nested-blocks-inner-blocks/)
を使用する場合は、`save` コールバック関数で `<InnerBlocks.Content/>` を使用して `
InnerBlocks` を保存する必要があります。

## 󠀁[その他の情報](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/static-dynamic-rendering/?output_format=md#%e3%81%9d%e3%81%ae%e4%bb%96%e3%81%ae%e6%83%85%e5%a0%b1)󠁿

 * [Static vs. dynamic blocks: What’s the difference?](https://developer.wordpress.org/news/2023/02/27/static-vs-dynamic-blocks-whats-the-difference/)
   | Developer Blog
 * [Block deprecation – a tutorial](https://developer.wordpress.org/news/2023/03/10/block-deprecation-a-tutorial/)
   | Developer Blog

[原文](https://github.com/WordPress/gutenberg/blob/trunk/docs/getting-started/fundamentals/static-dynamic-rendering.md)

公開日

2024年1月27日

最終更新

2026年8月11日

[  前へ: ブロックのマークアップ表現](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/markup-representation-block/)

[  次へ: ブロックエディターでの JavaScript の利用](https://ja.wordpress.org/team/handbook/block-editor/getting-started/fundamentals/javascript-in-the-block-editor/)