カスタムヘッダはバージョン2.1で導入されたテーマ機能です。カスタムヘッダーは、テーマ上部のヘッダーセクションに代表画像として選択されている画像です。
Custom Header is a theme feature introduced with Version 2.1. Custom header is an image that is chosen as the representative image in the theme top header section.
Appearance Header Screenを参照してください
テーマサポートを追加します
バージョン3.4以降、テーマは次のように、カスタムヘッダーをサポートするためにfunctions.phpファイルにadd_theme_support()を使用する必要があります。
Since Version 3.4, themes need to use add_theme_support() in the functions.php file to supports custom headers, like so:
add_theme_support( 'custom-header' );
使用しているデフォルトの引数を追加できることに注意してください。
Note that you can add default arguments using:
$defaults = array( 'default-image' => '', 'random-defa => false, 'width' => 0, 'height' => 0, 'flex-height => false, 'flex-width' => false, 'default-text-color'=> '', 'header-text' => true, 'uploads' => true, 'wp-head-callback' => '', 'admin-head-callback' => '', 'admin-preview-callback' => '', ); add_theme_support( 'custom-header', $defaults );
例
カスタムヘッダー画像を設定する
デフォルトのヘッダー画像980pxの幅と60pxの高さを設定します。
Set a default header image 980px width and 60px height:
$args = array( 'width' => 980, 'height' => 60, 'default-image' => get_template_directory_uri() . '/images/header.jpg', ); add_theme_support( 'custom-header', $args );
他のカスタムヘッダー画像をアップロードする
デフォルトのヘッダー画像を設定し、サイトの所有者は他の画像をアップロードすることができます:
Set a default header image and allow the site owner to upload other images:
$args = array( 'width' => 980, 'height' => 60, 'default-image' => get_template_directory_uri() . '/images/header.jpg', 'uploads' => true, ); add_theme_support( 'custom-header', $args );
柔軟なヘッダーを使用する
柔軟なヘッダーを設定する:
Set flexible headers:
$args = array( 'flex-width' => true, 'width' => 980, 'flex-width' => true, 'height' => 200, 'default-image' => get_template_directory_uri() . '/images/header.jpg', ); add_theme_support( 'custom-header', $args );
header.phpファイルにアップデートします。:
update your header.php file to:
<img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
関連
Theme Support: add_theme_support(), remove_theme_support(), current_theme_supports()
Theme Features: widgets, menus, post-formats, post-thumbnails, custom-background, custom-header, automatic-feed-links, editor-style