嗨,我正在为WP自定义添加选项。
大多数情况下,一切正常,但我的一个变量没有在预览窗口中刷新。
$wp_customize->add_setting(\'checkbox\', array(
\'capability\' => \'edit_theme_options\',
\'default\' => false,
));
$wp_customize->add_control(\'checkbox_control\', array(
\'settings\' => \'checkbox\',
\'label\' => __(\'Activate Coming Soon Page\', \'ln\'),
\'section\' => \'general_settings\',
\'type\' => \'checkbox\',
\'priority\' => 1,
));
这是我添加复选框的方式,这是我的签入函数。php
function template_redirect() {
if(true == get_theme_mod(\'checkbox\')) {
include (TEMPLATEPATH . \'/coming-soon.php\');
exit;
}
}
add_action( \'template_redirect\', \'template_redirect\' );
所以一切都正常~唯一的问题是,当您在WP Customize中并单击复选框时,预览窗口会重新加载页面,但不会显示更改。如果单击“保存并手动刷新”,则一切正常。
有什么建议可以解决这个问题吗?
非常感谢。
更新时间:
I found what is breaking WP CUSTOMIZER, it is the exit of the redirect. Is there another way how to fix this issue. I need to redirect to that page if the checkbox is TRUE
function template_redirect() {
if(true == get_theme_mod(\'checkbox\')) {
include (TEMPLATEPATH . \'/coming-soon.php\');
exit; !!!!!!!!!!!!!!!!!
}
}
add_action( \'template_redirect\', \'template_redirect\' );
SO网友:MBL
您是否尝试过显式添加\'transport\'
通话时选择$wp_customize->add_setting
?
e、 g。
$wp_customize->add_control(\'checkbox_control\', array(
\'settings\' => \'checkbox\',
\'label\' => __(\'Activate Coming Soon Page\', \'ln\'),
\'section\' => \'general_settings\',
\'type\' => \'checkbox\',
\'priority\' => 1,
\'transport\' => \'refresh\'
));
或者,您可以使用框架与WP主题定制器进行交互。例如,Slobodan躁狂呼叫有一个很好的
Customizer Boilerplate. 例如,要使用Customizer样板中的复选框,只需从Github将文件下载到主题的目录,在主题中包含调用
functions.php
定制样板(例如。
require( get_stylesheet_directory() . \'/customizer-boilerplate/customizer.php\' );
然后可以修改中提供的选项
options.php
只保留复选框:
/*
* ==============
* ==============
* Checkbox field
* ==============
* ==============
*/
\'new_checkbox_field\' => array(
\'setting_args\' => array(
\'default\' => true,
\'type\' => \'option\',
\'capability\' => $thsp_cbp_capability,
\'transport\' => \'refresh\',
),
\'control_args\' => array(
\'label\' => __( \'New checkbox field label\', \'my_theme_textdomain\' ),
\'type\' => \'checkbox\', // Checkbox field control
\'priority\' => 2
)
)