尝试将选项卡添加到wordpress定制器后出现错误500

时间:2019-01-14 11:15:08

标签: wordpress plugins

我正试图在我的wordpress定制器中添加一个标签。

我使用下一个代码:

add_action('customize_register','theme_costumizer_register');

function theme_costumizer_register($wp_customize){
    $wp_customize->add_section('facebook_new_section', array(
            'title'     =>  'Social Media',
            'priority'  =>  10
        ));
    $wp_customize->add_settings('facebook',
        array(
            'default'   =>  'http://facebook.com/ahiad'
        ));
    $wp_customize->add_control(new WP_Customize_Control($wp_customize,'txtFacebookAddress',
        array(
            'label'     =>  'Facebook Link',
            'section'   =>  'facebook_new_section',
            'type'      =>  'text'
            )));


}

问题是每次我在网站上运行这段代码时,都会出现500错误,无法在此处发现问题...

1 个答案:

答案 0 :(得分:2)

您正在使用不存在的$wp_customize->settings,请使用$wp_customize->setting

请尝试以下代码:

   add_action('customize_register','theme_costumizer_register');

function theme_costumizer_register($wp_customize){
    $wp_customize->add_section('facebook_new_section', array(
        'title'     =>  'Social Media',
        'priority'  =>  10
    ));

    $wp_customize->add_setting('facebook',
        array(
            'type' => 'theme_mod', // or 'option'
            'capability' => 'edit_theme_options',
            'theme_supports' => '', // Rarely needed.
            'default'   =>  'http://facebook.com/ahiad',
            'transport' => 'refresh', // or postMessage
            'sanitize_callback' => '',
            'sanitize_js_callback' => '', 

        ));
    $wp_customize->add_control('facebook',
        array(
            'label'     =>  'Facebook Link',
            'section'   =>  'facebook_new_section',
            'type'      =>  'text'
        ));   
}

我希望它将对您有所帮助。谢谢