WordPress主题定制器内容未在页面上显示

时间:2014-09-08 21:22:50

标签: php wordpress wordpress-theming

所有

我正在使用我为网站开发的自定义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>

该字段的内容未显示在页面上。

1 个答案:

答案 0 :(得分:4)

add_setting()正在注册错误的ID,add_control()在添加默认字段时不需要new WP_Customize_Control($wp_customize, ),仅在创建自定义WP_Customize_*类时才会显示。{/ p >

$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'
    )
 );