この記事は最後に更新してから1年以上経過しています。

新テーマ「Twenty Twenty-Three」にはfunctions.phpがない

説明

WordPress 6.1に同梱された新テーマ「Twenty Twenty-Three」を見てみると、そこには見慣れたfunctions.phpがない。Full Site Editing(FSE)対応テーマってこんな感じなのかと思いつつ、テーマの設定がどうなっているのか調べてみた。

ブロックベースのテーマ

テーマを「Twenty Twenty-Three」に切り替え、出力された内容を見てみると、サイト共通のfeedリンクが出力されている。このことからテーマに'automatic-feed-links'が適用されていることがわかったので、WordPressのソースコードを検索すると、wp-includes/theme.php の中に「_add_default_theme_supports」というプライベート関数が見つかった。

function _add_default_theme_supports() {
	if ( ! wp_is_block_theme() ) {
		return;
	}

	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'responsive-embeds' );
	add_theme_support( 'editor-styles' );
	/*
	 * Makes block themes support HTML5 by default for the comment block and search form
	 * (which use default template functions) and `` and `` shortcodes.
	 * Other blocks contain their own HTML5 markup.
	 */
	add_theme_support( 'html5', array( 'comment-form', 'comment-list', 'search-form', 'gallery', 'caption', 'style', 'script' ) );
	add_theme_support( 'automatic-feed-links' );

	add_filter( 'should_load_separate_core_block_assets', '__return_true' );
}

この関数はバージョン5.9.0で追加されたもので、setup_themeアクションのコールバック関数として定義されており、従来からテーマの設定を行う際に利用しているafter_setup_themeアクションより先に実行するものだった。

_add_default_theme_supports関数の中身を見てみると、 wp_is_block_theme関数によりテーマがブロックベースのテーマなのか判定し、ブロックベースのテーマでない場合はなにもしない。ブロックベースのテーマの場合は、 add_theme_support関数によりいくつかの機能を追加している。これらの機能に過不足があった場合は、テーマのfunctions.phpに記述することになるようだ。


最終更新 : 2022年10月06日 12:56


お勧め

wp_print_inline_script_tag(2021年4月19日 更新)

void wp_print_inline_script_tag( string $javascript [ , array $attributes = array() ] )
インラインJavaScriptを含むscript要素を出力する。

register_rest_route(2022年8月17日 更新)

bool register_rest_route( string $namespace, string $route [ , array $args = array() [ , bool $override = false ] ] )
REST APIのルートを登録する。

wp_determine_option_autoload_value(2024年7月22日 更新)

string wp_determine_option_autoload_value( string $option, mixed $value, mixed $serialized_value, boo l |string $autoload )
自動ロードのトリガー値を取得する。

single_tag_title(2018年5月27日 更新)

string single_tag_title( [ string $prefix = '' [ , bool $display = true ] ] )
投稿タグアーカイブページの投稿タグ名を取得し、パラメータ$displayがtrueならば表示する。$displayがfalseの場合は、文字列として返す。

home_url(2023年3月31日 更新)

string home_url( [ string $path = '' [ , string $scheme = null ] ] )
現在のブログ(サイト)のホームURLを取得する。ホームURLは、管理者ページの「設定」-「一般」の「サイトのアドレス(URL)」のこと。