• 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

関数リファレンス/add custom image header

提供: WordPress Codex 日本語版
< 関数リファレンス
2010年7月21日 (水) 15:35時点におけるMizuno (トーク | 投稿記録)による版 ({{原文|Function Reference/add_custom_image_header|83618}}<!-- 23:17, 3 March 2010 Esmi 版 -->)

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

このページ「関数リファレンス/add custom image header」は未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています

Description

Add callbacks for image header display.

The parameter $header_callback callback will be required to display the content for the 'wp_head' action. The parameter $admin_header_callback callback will be added to Custom_Image_Header class and that will be added to the 'admin_menu' action.

Usage

%%%<?php add_custom_image_header( $header_callback, $admin_header_callback ) ?>%%%

Parameters

$header_callback
callback) (必須) Call on 'wp_head' action.
初期値: なし
$admin_header_callback
callback) (必須) Call on administration panels.
初期値: なし

Return Values

(void) 
This function does not return a value.

Examples

Edit the file functions.php inside your theme and add the following code.

Four constants must be defined in order for the custom image header to work:

define('HEADER_TEXTCOLOR', 'ffffff');
define('HEADER_IMAGE', '%s/images/default_header.jpg'); // %s is the template dir uri
define('HEADER_IMAGE_WIDTH', 775); // use width and height appropriate for your theme
define('HEADER_IMAGE_HEIGHT', 200);

If you don't want to allow changing the header text color, add:

define('NO_HEADER_TEXT', true );

Then change the first definition to:

define('HEADER_TEXTCOLOR', '');

If you intend to create child themes use:

define('HEADER_IMAGE', get_bloginfo('stylesheet_directory') . '/images/banner.jpg');

Otherwise, you'll pick up the header image for the parent theme rather than the child.

Next you need to write two functions. One will be included in the site header. The second will be included in the admin header. Both of these functions are required. The smallest possible amount of code would be something like this, although you can do anything you need.

// gets included in the site header
function header_style() {
    ?><style type="text/css">
        #header {
            background: url(<?php header_image(); ?>);
        }
    </style><?php
}
// gets included in the admin header
function admin_header_style() {
    ?><style type="text/css">
        #headimg {
            width: <?php echo HEADER_IMAGE_WIDTH; ?>px;
            height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
        }
    </style><?php
}

Finish with calling the add_custom_image_header function with the two earlier function names as parameters:

add_custom_image_header('header_style', 'admin_header_style');

Taking this last step will make the Custom Header item appear in the Appearance menu. WordPress takes care of everything else.

Notes

Change Log

Since: 2.1.0

Source File

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

Related

最新英語版: WordPress Codex » Function Reference/add_custom_image_header最新版との差分