add_theme_support

説明

void add_theme_support( string $feature [ , mixed $args = true [ , mixed $... ] ] )
テーマの機能を設定する。

パラメータ

  • $feature
    機能名。主な機能名と対応バージョンは次の通り。
    機能名対応バージョン
    'post-thumbnails'2.9.0
    'automatic-feed-links'2.9.0
    'post-formats'2.9.0
    'custom-header'3.4.0
    'custom-background'3.4.0
    'html5'3.6.0
    'title-tag'4.1.0
    'custom-logo'4.5.0
    'customize-selective-refresh-widgets'4.5.0
    'starter-content'4.7.0
    'responsive-embeds'5.0.0
    'align-wide'5.0.0
    'dark-editor-style'5.0.0
    'disable-custom-colors'5.0.0
    'disable-custom-font-sizes'5.0.0
    'editor-color-palette'5.0.0
    'editor-font-sizes'5.0.0
    'editor-styles'5.0.0
    'wp-block-styles'5.0.0
    'core-block-patterns'5.5.0
    'editor-gradient-presets'5.6.0
    'experimental-link-color'5.6.0
    'custom-spacing'5.7.0
    'widgets-block-editor'5.8.0
    'block-template-parts'6.1.0
    'link-color'6.3.0
    'border'6.3.0
    'appearance-tools'6.3.0
    'editor-spacing-sizes'6.6.0
  • $args
    機能のパラメータを指定(省略時は、true)。

返り値

テーマ機能を登録できなかった場合はfalseを返す。


注意

自テーマのfunctions.phpにてadd_action関数を利用し、各種設定を行う関数内(Twenty Tenテーマではtwentyten_setup関数)で使用する。

add_action( 'after_setup_theme', 'twentyten_setup' );

なお3.0で追加されたナビゲーションメニューを追加する場合は、この関数ではなく、register_nav_menus関数を使用する。

パラメータ$featureによって$argsに指定する値が変わる。主なテーマ機能とその内容は次の通り。

$feature$argsの内容
'post-thumbnails'true(省略可)
'automatic-feed-links'true(省略可)
'post-formats'サポートする投稿フォーマット('aside'、'image'、'video'、'quote'、'link'、'gallery'、'status'、'audio'、'chat')を格納した配列
'custom-header'以下の連想配列
array(
	'default-image'          => パス名(省略時''),
	'random-default'         => bool(省略時false),
	'width'                  => 数値(省略時0),
	'height'                 => 数値(省略時0),
	'flex-height'            => bool(省略時false),
	'flex-width'             => bool(省略時false),
	'default-text-color'     => 文字列(省略時''),
	'header-text'            => bool(省略時true),
	'uploads'                => bool(省略時true),
	'wp-head-callback'       => コールバック(省略時''),
	'admin-head-callback'    => コールバック(省略時''),
	'admin-preview-callback' => コールバック(省略時''),
	'video'                  => bool(省略時false),
	'video-active-callback'  => コールバック(省略時'is_front_page'),
);
'custom-header-uploads'true(省略可)
'custom-logo'以下の連想配列
array(
	'width'                => 数値(省略時null),
	'height'               => 数値(省略時null),
	'flex-width'           => bool(省略時false),
	'flex-height'          => bool(省略時false),
	'header-text'          => 文字列(省略時''),
	'unlink-homepage-logo' => bool(省略時false), // [5.5.0]追加
);
'html5'HTML5向けのマークアップ('search-form'、'comment-form'、'comment-list'、'gallery'、'caption')を格納した配列
[5.3.0]'script'と'style'が追加された。
'title-tag'true(省略可)
'custom-background'キー('default-color'(文字列)、'default-attachment'(文字列))の値を格納した連想配列
'customize-selective-refresh-widgets'true(省略可)
'starter-content'キー('widgets'(連想配列)、'posts'(連想配列)、'attachments'(連想配列)など)の値を格納した連想配列
'featured-content'キー('featured_content_filter'(文字列)、'max_posts'(数値))の値を格納した連想配列
'responsive-embeds'true(省略可)
'align-wide'true(省略可)
'dark-editor-style'true(省略可、'editor-styles'も必要)
'disable-custom-colors'true(省略可)
'disable-custom-font-sizes'true(省略可)
'editor-color-pallete'連想配列を含む配列(連想配列のキーは'name'、'slug'、'color')
'editor-font-sizes'連想配列を含む配列(連想配列のキーは'name'、'shortName'、'size'、'slug')
'editor-gradient-presets'連想配列を含む配列(連想配列のキーは'name'、'gradient'、'slug')
'editor-styles'true(省略可)
'wp-block-styles'true(省略可)
'core-block-patterns'標準でtrue
'experimental-link-color'true(省略可)
'custom-spacing'true(省略可)
'widgets-block-editor'true(省略可)
'block-template-parts'true(省略可)
'link-color'true(省略可)
'border'true(省略可)
'appearance-tools'true(省略可)
'editor-spacing-sizes'連想配列を含む配列(連想配列のキーは'name'、'slug'、'size')

本関数のパラメータは可変数で、第2パラメータの内容が配列のインデックス0の値として、第3パラメータの内容がインデックス1の値として、第4パラメータの内容がインデックス2の値としてシステム内に保存される。

[5.6.0]パラメータ$featureが'post-formats'で値が配列以外の場合、警告メッセージ('You need to pass an array of post formats.'の翻訳テキスト)が表示される。

[5.7.0]パラメータ$featureに追加された'custom-spacing'を指定しないと、ブロックエディターの各ブロックにて「サイズ(Dimensions)」に「パディング(Padding)」が表示されない。


使用例

  • 投稿編集ページに「アイキャッチ画像」を追加する。
    <?php add_theme_support( 'post-thumbnails' ); ?>
  • 投稿ページに「フォーマット」を追加する。
    <?php add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) ); ?>

フィルター

実行するフィルターはありません。

アクション

実行するアクションはありません。

ソースファイル

/wp-includes/theme.php

最終更新 : 2024年07月22日 14:50



お勧め

個人データのエクスポートメール向けに追加された新フィルター(2020年4月2日 更新)

先週「WordPress 5.4 RC3」が公開され、正式リリースまであと1週間。ブロックエディターの機能強化が目立つわけですが、地味な変更点もちらほらと。今回はその中の1つ、「個人データのエクスポート」機能に関連するフィルターを紹介する。

決まった値を返すだけの関数群(2018年5月27日 更新)

WordPressのソースコードを眺めているとフィルター関数名で'__return_○○'が指定されている部分を時々見かけます。それらの関数定義を見てみると、すべて決まった値を単純に返すだけでした。これらの関数がちょっと気になったので、まとめてみました。

サイドバーの初期化はwidgets_initアクションで(2011年7月14日 更新)

ウィジェットを使ってみたくなり新テーマ「Twenty Eleven」を覗いてみると、codexに記載されていた内容と少し違っている。これって「Twenty Ten」ですでに変更されていたんだね。

Gutenbergでカスタムフィールドを使う(2018年8月10日 更新)

Gutenbergの新エディターではカスタムフィールドのウィジェットが表示されない。既存のカスタムフィールドのデータはなくなるわけでないので、新エディター上で編集・更新できないか調べてみた。

favicon.icoがWordPressロゴになる!?(2020年2月25日 更新)

先週「WordPress 5.4 Beta2」が公開され、来月末には正式リリース。タイミングよく三連休だったので、1つ前の「ニュース」で紹介されていた変更点から確認してみた。