所有
我正在使用我为网站开发的自定义wordpress主题.我在页脚的左侧有一个字段用于邮寄地址,我希望通过wordpress中的主题自定义程序对其进行编辑.我已将相关字段添加到自定义程序,但该字段的内容未显示在页面上.
在functions.PHP中,以下代码将字段添加到主题定制器:
//Adds footer address to theme customizer
function sanitize_footer_address($input){
return strip_tags(stripslashes($input));
}
function portfolio_customize_register($wp_customize){
$wp_customize->add_section(
'Footer',
array(
'title' => __('Left Footer Content', 'portfolio'),
'priority' => 200
)
);
$wp_customize->add_setting(
'footer_address',
array(
'default' => '100 Main Street | Anytown, USA',
'sanitize_callback' => 'sanitize_footer_address'
)
);
$wp_customize->add_control( new WP_Customize_Control(
$wp_customize,
'footer_address',
array(
'label' => 'Address to appear on left side of footer',
'section' => 'Footer',
'settings' => 'footer_address_text',
'type' => 'text'
)
)
);
}
add_action(customize_register, portfolio_customize_register);
<p class="col md-4 text-muted" id="footer_address"><?PHP echo get_theme_mod('footer_address_text'); ?></p>
解决方法:
add_setting()正在注册错误的ID,而add_control()
在添加默认字段时不需要新的WP_Customize_Control($wp_customize),仅在创建自定义WP_Customize_ *类时.
$wp_customize->add_setting(
'footer_address_text',
array(
'default' => '100 Main Street | Anytown, USA',
'sanitize_callback' => 'sanitize_footer_address'
)
);
$wp_customize->add_control(
'footer_address',
array(
'label' => 'Address to appear on left side of footer',
'section' => 'Footer',
'settings' => 'footer_address_text',
'type' => 'text'
)
);