WordPress「add_theme_support」でカスタム背景を有効化する
WordPressのカスタム背景
を有効化すると、カスタマイザーから背景色を変更できるようになったり、背景画像を設定できるようになる。
カスタム背景の有効化
body_class()
とwp_head()
を配置した上で、functions.php
にカスタム背景を有効化するコードを記述する。
// カスタム背景
add_theme_support('custom-background');
外観>カスタマイズ
の左パネルに、色
と背景画像
が表示されるようになる。
左パネル

色の設定

背景画像の設定

出力されるスタイル
1bodyタグにcustom-background
というクラス名が付与される。
<body id="page-top" class="home blog custom-background">
2headタグにインラインでスタイルが追加される。
<style type="text/css" id="custom-background-css">
body.custom-background { background-color: #dd3333; }
</style>
初期値を設定する
$args = array(
'default-color' => '000000',
'default-image' => '%1$s/images/background.jpg',
);
add_theme_support( 'custom-background', $args );
Related Tags