[英]customize_register is not showing to front end
I have registered this function to the theme customization. 我已经将此功能注册到主题定制中。 But It's not showing to the front end(customize section).
但这并没有显示在前端(自定义部分)。
// Header section customize field
function header($wp_customize){
$wp_customize->add_section('header_section', array(
'title' => 'Header Section'
));
$wp_customize->add_setting('header_headline', array(
'default' => 'Hello, I\'m'
));
$wp_customize->add_control(new WP_Customize_control($wp_customize, 'header_headline_control', array(
'label' => 'Headline',
'section' => 'header_section',
'setting' => 'header_headline'
)));
}
add_action('customize_register','header');
header_headline_control
is not correct in add_control()
. header_headline_control
在add_control()
不正确。 You need to keep header_headline
. 您需要保留
header_headline
。 It should be same as in add_seting()
. 它应该与
add_seting()
相同。 Otherwise it wont work. 否则它将无法正常工作。
See documentation https://developer.wordpress.org/themes/customize-api/customizer-objects/ 参见文档https://developer.wordpress.org/themes/customize-api/customizer-objects/
A well-known example is here: 一个著名的例子在这里:
// Header section customize field
function alpha_customize($wp_customize)
{
$wp_customize->add_setting('header_bg_color', array(
'default' => "#4285f4",
'transport' => 'refresh'
));
$wp_customize->add_section('alpha_color_theme_section', array(
'title' => __('Color', 'alpha'),
'priority' => 30
));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'theme_color', array(
'label' => __('Header Color', 'alpha'),
'section' => 'alpha_color_theme_section',
'settings' => 'header_bg_color'
)));
}
add_action('customize_register', 'alpha_customize');
// Change and reflect value accordingly
function alpha_example_head()
{
$header_color = get_theme_mod('header_bg_color', '#4285f4');
$style = <<<EOD
<style>
.header h1.heading a, h3.tagline{
color:{$header_color};
}
</style>
EOD;
echo $style;
}
add_action('wp_head', 'alpha_example_head', 1100);
For text input 用于文字输入
// Header section customize field
function alpha_header($wp_customize)
{
// Save settings to database
$wp_customize->add_setting('alpha_header_headline', array(
'default' => 'Hello, I\'m',
'transport' => 'refresh'
));
//Add a section for you settings in customizer option
$wp_customize->add_section('alpha_header_section', array(
'title' => __('Header title', 'alpha'),
'priority' => 30 //the lowest the number the highest the input field will get preference
));
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'header-text',
array(
'label' => __( 'Header Title', 'alpha' ),
'section' => 'alpha_header_section',
'settings' => 'alpha_header_headline',
'type' => 'text'
)
)
);
}
add_action('customize_register', 'alpha_header');
then update your text value using javascript. 然后使用javascript更新您的文本值。 Also replace alpha with your theme name.
也用您的主题名称替换alpha。 A full reference can be found here: https://codex.wordpress.org/Theme_Customization_API
完整的参考资料可以在这里找到: https : //codex.wordpress.org/Theme_Customization_API
Thanks, let me know if this works for you. 谢谢,让我知道这是否适合您。
I want to add image thus I used 我想添加图像,所以我用了
// Provider Image
$wp_customize->add_setting('header-image');
$wp_customize->add_control(new WP_Customize_Cropped_Image_Control($wp_customize, 'header-image', array(
'label' => 'Add Image',
'section' => 'header-section',
'settings' => 'header-image',
'width' => 426,
'height' => 642
)));
And echo 和回声
<img src="<?php echo wp_get_attatchment_url(get_theme_mod('header-image')) ?>">
Uploading image working fine, but the page is just loading. 上传图片效果很好,但是页面正在加载中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.