要使用颜色选择器添加设置,请尝试以下代码:
const COLOR_SECTION = "color_section";
const SETTING_COLOR1 = "color1";
add_action("customize_register", function (\WP_Customize_Manager $wp_customize) {
$wp_customize->add_section(
COLOR_SECTION
,
[
"title" => "Color section",
"priority" => 1,
]
);
$wp_customize->add_setting(
SETTING_COLOR1
,
[
"default" => get_theme_mod(SETTING_COLOR1),
"type" => "theme_mod",
]
);
$wp_customize->add_control(
SETTING_COLOR1
,
[
"label" => "Color 1",
"type" => "color",
"section" => COLOR_SECTION,
]
);
});
// example of utilisation of the color
add_filter("the_title", function ($t) {
$color1 = get_theme_mod(SETTING_COLOR1);
return "$t - $color1";
});