add_theme_support

Sponsored Link

特定のテーマ機能のサポートを登録するためのテーマあるいはプラグインを許可します。テーマから呼び出された場合、テーマのfunctions.phpファイル内で動作するために行う必要があります。フックに接続されている場合もプラグインから呼び出すことも出来ます。

フックに接続されている場合、after_setup_theme似する必要があります。initフックは幾つかの機能のために遅すぎるかもしれません。

Sponsored Link

Allows a theme or plugin to register support of a certain theme feature. If called from a theme, it should be done in the theme’s functions.php file to work. It can also be called from a plugin if attached to a hook.

If attached to a hook, it must be after_setup_theme. The init hook may be too late for some features.

add_theme_supportのファンクションタグ使用方法

<?php add_theme_support( $feature ); ?>

add_theme_supportのパラメーター

$feature

(string) (required) 機能のために追加された名前です。
デフォルト:なし

(string) (required) Name for the feature being added.
Default: None

  • ‘post-formats’
  • ‘post-thumbnails’
  • ‘custom-background’
  • ‘custom-header’
  • ‘automatic-feed-links’

追加可能な機能

投稿フォーマット

この機能はテーマのために投稿フォーマットのサポートを有効にしますこの機能はバージョン3.1で利用できるようになりました。子テーマを使用する時、add_theme_support( ‘post-formats’ )は、それを追加せず、親テーマによて定義されたフォーマットを上書きすることに注意してください。

This feature enables post-formats support for a Theme. This feature became available with Version 3.1. When using Child Themes, be aware that add_theme_support( ‘post-formats’ ) will override the formats as defined by the parent theme, not add to it.

add_theme_support( 'post-formats' );

特定フォーマットを有効にするには:

To enable specific formats:

add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );

フォーマットを使用する

投稿に割り当てられた’quote’投稿フォーマットがある場合にチェックします。

Check if there is a ‘quote’ post format assigned to the post.

// テーマ内にsingle.php, page.php あるいはカスタム投稿タイプ。 custom post typein your theme single.php, page.php or custom post type
if ( has_post_format( 'quote' ) ) {
  echo 'This is a quote.';
}

投稿サムネイル

この機能はテーマのために投稿サムネイルのサポートを有効にします。この機能はバージョン2.9で利用できるようになりました。オプションでこの機能を有効にするための投稿タイプの配列と第二引数を渡す事ができることに注意してください。

This feature enables post-thumbnail support for a Theme. This feature became available with Version 2.9. Note that you can optionally pass a second argument with an array of the post types for which you want to enable this feature.

add_theme_support('post-thumbnails');

投稿のためのみに有効にするには:

add_theme_support( 'post-thumbnails', array( 'post' ) );

あるいはページのみの場合:

Or only Pages:

add_theme_support( 'post-thumbnails', array( 'page' ) );

ページのためではなく、投稿と”movie”投稿タイプのために有効にします。

Enable for Posts and “movie” post type but not for Pages.

add_theme_support( 'post-thumbnails', array( 'post', 'movie' ) );

この機能はinitフックが発生する前に呼び出す必要があります。
functions.php内あるいはafter_setup_themeフックに接続されている関数内に直接配置する必要があることを意味しています。

カスタム投稿タイプでは、register_post_type関数と同様に使用して投稿サムネイルを追加することも出来ます。

This feature must be called before the init hook is fired. That means it needs to be placed directly into functions.php or within a function attached to the after_setup_theme hook:

For custom post types, you can also add post thumbnails using the register_post_type function as well.

サムネイルを使用する方法

サムネイルを表示する:

Displaying thumbnails:

// テーマのindex.php か single.php か、カスタムテンプレートに。in your theme index.php or single.php or custom templates
the_post_thumbnail();

それを表示する前に投稿に割り当てられた投稿サムネイルがある場合にチェックします。

Check if there is a post thumbnail assigned to the post before displaying it.

if ( has_post_thumbnail() ) {
  the_post_thumbnail();
}

カスタム背景

バージョン3.4に実装されます。それまでは、add_custom_background()を使用して、add_custom_background()が3.4で廃止されることに注意してください。

Coming in Version 3.4. Until then, use add_custom_background() and note that it will be deprecated in 3.4.

WordPressが少なくともバージョン3.4であるかどうかを判断するための、この短い関数(注:これはデフォルトのWPの関数ではありません)を使用することができます。したがって、3.4への移行時には、別の方法でそれらを使用することによって、両方の関数をサポートすることができます。

You can use this short function (note: this is not a default WP function) to determine if WordPress is at least version 3.4 or not. So during the transition to 3.4, you can support both functions by using them in the alternative:

<?php if( is_wp_version( '3.4' ) ) add_theme_support( 'custom_background' ); 
else add_custom_background( $args ); ?>

カスタムヘッダー

バージョン3.4に実装されます。それまでは、add_custom_image_header()を使用して、add_custom_image_header()が3.4で廃止されることに注意してください。

Coming in Version 3.4. Until then, use add_custom_image_header() and note that it will be deprecated in 3.4.

WordPressが少なくともバージョン3.4であるかどうかを判断するための、この短い関数(注:これはデフォルトのWPの関数ではありません)を使用することができます。したがって、3.4への移行時には、別の方法でそれらを使用することによって、両方の関数をサポートすることができます。

You can use this short function (note: this is not a default WP function) to determine if WordPress is at least version 3.4 or not. So during the transition to 3.4, you can support both functions by using them in the alternative:

<?php if( is_wp_version( '3.4' ) ) add_theme_support( 'custom_header' ); 
else add_custom_image_header( $args ); ?>

フィードリンク

この機能はヘッド内への投稿とコメントのRSSフィードのリンクを可能にします。これは非推奨のautomatic_feed_linksの代わりに使用する必要があります。この機能はバージョン3.0で利用できるようになりました。

This feature enables post and comment RSS feed links to head. This should be used in place of the deprecated automatic_feed_links. This feature became available with Version 3.0.

add_theme_support( 'automatic-feed-links' );

マルチサイト

マルチサイトをインストールした”Featured Image”メタボックスを表示するには、ネットワーク管理内の、ネットワーク管理者設定サブパネル#Upload_Settings、メディアアップロードボタンオプションで、アップロードファイルタイプを許可したアップデートを確認し、。デフォルトはオフです。

To show the “Featured Image” meta box in mulsite installation, make sure you update the allowed upload file types, in Network Admin, Network Admin Settings SubPanel#Upload_Settings, Media upload buttons options. Default is off.

注釈

次のパラメーターは読取り専用で、current_theme_supports()のコンテキスト内で使用する必要があります。:

The following parameters are read only, and should only be used in the context of current_theme_supports():

  • custom-headers: Use add_custom_image_header() instead.
  • custom-background: Use add_custom_background() instead.
  • editor-style: Use add_editor_style() instead.
  • menus: Use register_nav_menu() or register_nav_menus() instead.
  • widgets: Use register_sidebar() or register_sidebars() instead.

変更ログ

  • 3.1: Added ‘post-formats’. (Ticket #14746)
  • 3.0: Added ‘automatic-feed-links’ feature, which was previously a separate function.
  • 2.9: Introduced with ‘post-thumbnails’ feature.

    ソースファイル

    add_theme_support()は、wp-includes/theme.php内に位置しています。

    add_theme_support() is located in wp-includes/theme.php.

    関連ファンクションタグ

    Theme Support: add_theme_support(), remove_theme_support(), current_theme_supports()
    Theme Features: post-thumbnails, menus, widgets, post-formats, custom-background, custom-header, editor-style, automatic-feed-links

  • Sponsored Link