WordPress3.4からadd_theme_supportに、
カスタムヘッダーとカスタム背景のパラメーターが追加されます。
この変更点を書いて行きたいと思います。
※この記事は現時点での開発版で確認しながら記述していますが、
正式リリース時で変更する可能性がありますので、ご了承ください。
Twenty ElevenとCodex(本家)を見ながら、
WordPress3.4の新機能テーマカスタマイザーを見ていたのですが、
ちょっとテーマを作成する上で色々変更点が出ているな〜と、
現時点で分かっていることを纏めてみようと思います。
WordPress3.4からadd_theme_supportにパラメータが追加
add_custom_image_header( $args );
は、
add_theme_support( 'custom-header' );
に置き換わります。
add_custom_background( $args );
は、
add_theme_support( 'custom-background' );
に置き換わります。
なので、現状では下記のように書くといいようです。
カスタム背景の場合
<?php if( is_wp_version( '3.4' ) ) add_theme_support( 'custom-background' ); else add_custom_background( $args ); ?>
TwentyElevenの例
TwentyElevenの場合は若干手が加えられているので、そのままでは動かないので、ちょっとソースを変えています。
add_theme_support( 'custom-background', array( 'default-color' => "fff", ) ); // Add support for custom backgrounds.
カスタムヘッダーの場合
<?php if( is_wp_version( '3.4' ) ) add_theme_support( 'custom-header' ); else add_custom_image_header( $args ); ?>
TwentyElevenの例
実際にTwentyElevenでこの箇所を見てみると、
$custom_header_supportに配列を入れて、
add_theme_supportに$custom_header_supportを入れています。
これが3.4からのadd_theme_support( ‘custom-header’ ); に対応した新しい書き方です。
// カスタムヘッダーのサポートを追加します。 $custom_header_support = array( // デフォルトのヘッダーテキストカラーを指定します。 'default-text-color' => '000', // カスタムヘッダーの高さと幅を指定します。 'width' => apply_filters( 'lovelog28_header_image_width', 530 ), 'height' => apply_filters( 'lovelog28_header_image_height', 200 ), // 高さを自由に決めるか否か。 'flex-height' => true, // デフォルトで画像をランダム表示しますか? 'random-default' => true, // ヘッダーをスタイリングするためのコールバックを指定します。 'wp-head-callback' => 'lovelog28_header_style', // 管理画面でヘッダープレビューをスタイリングするためのコールバックを指定します。 'admin-head-callback' => 'lovelog28_admin_header_style', // 管理画面でヘッダープレビューを表示するために使用するコールバックを指定します。 'admin-preview-callback' => 'lovelog28_admin_header_image', ); add_theme_support( 'custom-header', $custom_header_support );
なお、3.4以下のバージョンにもちゃんと対応するようにされています。
今までの古い書き方ですね。
if ( ! function_exists( 'get_custom_header' ) ) { // これはWordPress3.4までの古いバージョンとの互換性を保つソースです。 define( 'HEADER_TEXTCOLOR', $custom_header_support['default-text-color'] ); define( 'HEADER_IMAGE', '' ); define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] ); define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] ); add_custom_image_header( $custom_header_support['wp-head-callback'], $custom_header_support['admin-head-callback'], $custom_header_support['admin-preview-callback'] ); add_custom_background(); }
恐らくadd_custom_image_header( $args );とadd_custom_background( $args );は、今後非推奨になっていくのではないかと思います。
参照
CODEXのカスタム背景とカスタムヘッダーのページを翻訳しました。
add_theme_supportの引数の使い方など説明されているので、一度確認することをおすすめします。