php - 如何在子主题中覆盖父customizer.php
问题描述
我是 Wordpress 和 PHP 的新手,我正在尝试为 memberlite 主题创建一个子主题。我想向定制器添加自定义配色方案,但我不知道如何取消注册父主题的 customizer.php,或修改当前配色方案。(我不确定哪种方法是正确的)。
在父主题functions.php中:
/* Customizer additions. */
require_once get_template_directory() . '/inc/customizer.php';
理想情况下,我想取消需要该文件并添加我自己的文件。
任何帮助,将不胜感激。
解决方案
要使用颜色选择器添加设置,请尝试以下代码:
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";
});
推荐阅读
- javascript - 使用 JavaScript 处理日期和时间字符串
- z3 - 证明任意基数中两位编码的内射性
- .net - IIS 无权访问证书存储
- python - 图像处理 - 将斑驳的白色形状变成固体
- c# - 根据 IEnumerable 从 IDictionary 中选择子集
并返回 IEnumerable - ios - 尝试将图像上传到 Firebase 错误:“StorageMetadata”类型的值没有成员“downloadURL”-SWIFT 4
- javascript - 可变阶段不断返回未定义
- python - Keras 回调以同时监控验证和训练的准确性
- ruby - Ruby 中的多线程
- javascript - 单击外部时我的模式没有关闭