您的代码很好,我认为您缺少前端部分,以下是完整的代码functions.php
:
/* Customizer fields */
function your_customizer_settings($wp_customize) {
$wp_customize->add_section(\'footer_section\', array(
\'title\' => __(\'Footer Section\', \'healthtech\'),
\'panel\' => \'\',
));
/*
* Settings for copyright text
*/
$wp_customize->add_section(\'footer_section\', array(
\'title\' => __(\'Footer Section\', \'healthtech\'),
\'panel\' => \'\',
));
/*
* Settings for copyright text
*/
$wp_customize->add_setting(\'copyright_text\', array(
\'default\' => \'2342\',
\'transport\' => \'postMessage\'
));
$wp_customize->add_control(new WP_Customize_Control($wp_customize, \'copyright_text\', array(
\'label\' => __(\'Copyright Text\', \'healthtech\'),
\'section\' => \'footer_section\',
\'settings\' => \'copyright_text\',
)
)
);
$wp_customize->selective_refresh->add_partial(\'copyright_text\', array(
\'selector\' => \'span#copy-write\', // You can also select a css class
\'render_callback\' => \'check_copy_right_text\',
));
}
// Customizer action
add_action(\'customize_register\', \'your_customizer_settings\');
function check_copy_right_text(){
echo get_theme_mod(\'copyright_text\');
}
把这个放在
front-end
因为它是版权文本让我们假设
footer.php
:
<span id="copy-write"><?php check_copy_right_text(); ?></span>
如果转到customizer,您应该会看到
Edit Shortcut Button
像这样:
如果没有,您将不得不添加一些CSS来更好地定位按钮,您可以将该CSS添加到
style.css
或者创建一个CSS文件,仅用于更正按钮如果您有更多需要CSS的按钮,请记住使用
add_action( \'customize_preview_init\', \'my_function_with_wp_enqueue_with_my_css_only_for_the_customizer\' );
我在您的设置中添加了一个额外值:
$wp_customize->add_setting(\'copyright_text\', array(
\'default\' => \'2342\',
\'transport\' => \'postMessage\' //this one
));
如果不设置
transport
到
postMessage
整个预览将重新加载,因为它将默认为
refresh
, 这样,只有位置(即所谓的选择性刷新部分)才会更新。
我建议你阅读this 和this.
请不要犹豫,这是一项新功能,我正在添加Selective Refresh Partials
我所有的主题选项。
顺便说一下,对于呈现谷歌地图(或类似地图)的选项,您需要添加JavaSCript。