add_custom_image_header

Sponsored Link

ヘッダー画像を表示するためにコールバックを追加します。

$header_callbackコールバックのパラメーターは、’wp_head’アクションの内容を表示するために必要となります。$admin_header_callbackコールバックのパラメーターは、Custom_Image_Headerを追加して、’admin_menu’アクションを追加します。

Sponsored Link

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.

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

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

add_custom_image_headerのパラメーター

$header_callback

(callback) (required) ‘wp_head’アクションに呼び出します。

(callback) (required) Call on ‘wp_head’ action.

Default: None

$admin_header_callback

(callback) (required) 管理パネルに呼び出します。

(callback) (required) Call on administration panels.

Default: None

戻り値

(void)

この関数は値を返しません。

This function does not return a value.

テーマ内のfunctions.phpファイルを編集して、次のコードを追加します。

4つの定数は、カスタムイメージヘッダーを動作するために定義されなければなりません。

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');

でなければ、子でなく親テーマのヘッダーイメージをピックアップします。

次に、2つの関数を記述する必要があります。1つは、サイトヘッダーに含まれます。2つ目は、管理ヘッダーに含まれます。これら両方の機能が必要となります。コードの最小可能量は、必要な事を行う事ができるとはいえ、このようになるだろう。

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
}&#91;/php&#93;

&#91;php&#93;// 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
}&#91;/php&#93;

<p>パラメーターとして2つの以前の関数名とadd_custom_image_headerを呼び出すと完了します。:</p>
<blockquote>Finish with calling the add_custom_image_header function with the two earlier function names as parameters:</blockquote>
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.

注釈

用途:Custom_Image_Header。管理パネルの表示に$admin_header_callbackをセットアップします。

Uses: Custom_Image_Header. Sets up for $admin_header_callback for administration panel display.

変更ログ

Since: 2.1.0

ソースファイル

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

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

Sponsored Link