ワードプレスのカスタムヘッダー追加方法


Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /home/webstyle/php-fan.org/public_html/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /home/webstyle/php-fan.org/public_html/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

自作テーマの場合だとヘッダー画像を入れ替えるヘッダーメニューが表示されません。

作る必要があります。デフォルトテーマだとあります(twentyten,twentyeleven,twentytwelve)

ワードプレス3.4以降だとadd_custom_image_header()とadd_custom_background()は非推奨となってしまったのでadd_theme_support(‘custom-header’)を利用します。
ここのページに載っていました。WordPress.org


スポンサーリンク

▼functions.php

functions.phpに以下のように記述します。

$defaults = array(
	'default-image'          => '%s/images/header.jpg', //デフォルト画像',
	'random-default'         => false, //ランダム表示
	'width'                  => 940, //幅
	'height'                 => 100, //高さ
	'flex-height'            => false, //フレキシブル対応(高さ)
	'flex-width'             => false, //フレキシブル対応(幅)
	'default-text-color'     => '#999999', //デフォルトのテキストの色
	'header-text'            => true, //ヘッダー画像上にテキストを表示する
	'uploads'                => true //ファイルアップロードを許可する
);
 
add_theme_support( 'custom-header', $defaults );

▼header.php

header.phpに設定するヘッダーのimgを記述します。

<img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />

これで以上です。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です