【发布时间】:2014-11-02 04:59:36
【问题描述】:
全部
我正在使用为网站开发的自定义 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);
在footer.php模板中,相关标记为:
<p class="col md-4 text-muted" id="footer_address"><?php echo get_theme_mod('footer_address_text'); ?></p>
该字段的内容不显示在页面上。
【问题讨论】:
标签: php wordpress wordpress-theming