- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
カスタムヘッダー
このページ「カスタムヘッダー」は未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています。
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.
See also Appearance Header Screen.
目次
Adding 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-default' => 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 );
Example
Set a custom header image
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 );
Upload other custom header images
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 );
Use flexible headers
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 );
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="" />
Related
テーマサポート:
add_theme_support(),
remove_theme_support(),
current_theme_supports()
テーマ機能:
サイドバー,
ナビゲーションメニュー,
投稿フォーマット,
投稿サムネイル,
カスタム背景,
カスタムヘッダー,
自動フィードリンク,
html5,
コンテンツ幅,
editor-style
最新英語版: WordPress Codex » Custom Headers (最新版との差分)