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
    'widgets-block-editor'5.8.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(省略可)
'widgets-block-editor'true(省略可)

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

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


使用例

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

フィルター

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

アクション

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

ソースファイル

/wp-includes/theme.php

最終更新 : 2021年08月10日 14:04



お勧め

5.5で非推奨になる関数名について(2020年8月12日 更新)

来月にリリースされるWordPress 5.5に向けてBeta 1、2と公開が続いている。「WordPress 5.5 Beta 2(以降Beta 2)」のソースコードを見ていくと、いくつかの関数が非推奨になるようだ。

meta_compare_key使ってみた(2019年3月19日 更新)

ブロックエディターの登場により、標準のカスタムフィールドを使う機会はかなり減った気がする。そんな中、5.1.0で追加されたのが、カスタムフィールド名(メタキー)に含まれる文字列を指定する'meta_compare_key'キーだ。

プラグインの設定ページもレスポンシブ対応(2014年6月3日 更新)

レスポンシブ対応したWordPressの管理画面。プラグインやテーマのカスタマイズで管理画面を拡張しているなら、切り替わるタイミングはきっちり押さえておきたいところではないだろうか。

初期化に関連するアクションのおさらい(2013年11月27日 更新)

いつも何気なくfunctions.phpで使っているafter_setup_themeアクションやinitアクション。普段はあまり意識していなかったが、ふとしたことからどんな順番に呼び出されるのか気になってしまい、ちょっと調べてみた。

全投稿を取得するのはnopaging=1でいい(2011年8月31日 更新)

query_posts関数(またはWP_Queryクラス)を使う場合、取得する件数の指定を省略すると管理者ページの「表示設定」-「1ページに表示する最大件数」の指定値分だけの投稿情報を取得する。それでは条件にマッチするすべての投稿情報を取得するには?