首页 > 解决方案 > 如何在子主题中覆盖父customizer.php

问题描述

我是 Wordpress 和 PHP 的新手,我正在尝试为 memberlite 主题创建一个子主题。我想向定制器添加自定义配色方案,但我不知道如何取消注册父主题的 customizer.php,或修改当前配色方案。(我不确定哪种方法是正确的)。

在父主题functions.php中:

/* Customizer additions. */
require_once get_template_directory() . '/inc/customizer.php';

理想情况下,我想取消需要该文件并添加我自己的文件。

任何帮助,将不胜感激。

标签: phpwordpresschild-theming

解决方案


要使用颜色选择器添加设置,请尝试以下代码:

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";

});

推荐阅读