ADD_ACTION CUSTOM_REGISTER无效

时间:2016-05-31 作者:J. Doe

我已经在这方面工作了很长时间,但无法修复它。我只是想让下面的函数工作,但它拒绝这样做。

我已经把它放在函数中了。我的主题的php。

function options( $wp_customize ) {
    $wp_customize->add_control(
        \'copyright_textbox\',
        array(
            \'label\' => \'Copyright text\',
            \'section\' => \'example_section_one\',
            \'type\' => \'text\'
        )
    );
}
add_action( \'customize_register\', \'options\' );
即将放弃,但我最后的希望是这样。在这段代码中,我的仇恨是什么?我需要做什么来修复它?

1 个回复
最合适的回答,由SO网友:Capiedge 整理而成

您始终需要确保定义了三件事(节、设置和控制)。

如果要将控件添加到已定义的节,即。title_tagline, 然后,您不需要重新注册它,而是始终定义设置和控件。

//adding setting for copyright text
add_action(\'customize_register\', \'theme_copyright_customizer\');

function theme_copyright_customizer($wp_customize) {
    //adding section in wordpress customizer   
    $wp_customize->add_section(\'copyright_extras_section\', array(
        \'title\'          => \'Copyright Text Section\'
    ));

    //adding setting for copyright text
    $wp_customize->add_setting(\'text_setting\', array(
        \'default\'        => \'Default Text For copyright Section\',
    ));

    $wp_customize->add_control(\'text_setting\', array(
        \'label\'   => \'Copyright text\',
        \'section\' => \'copyright_extras_section\',
        \'type\'    => \'text\',
    ));
}
希望有帮助!

相关推荐

自定义发布类型的POST_ROW_ACTIONS

我正在使用this 在WordPress Admin中具有重复post函数的代码。但是,当我为自定义帖子类型添加过滤器时,如下所示:add_filter( \'directory_row_actions\', \'rd_duplicate_post_link\', 10, 2 ); (自定义帖子类型的注册名称为directory) - 它不会将其添加到条目标题下的操作行中。当我为帖子或页面执行此操作时,如下所示:add_filter( \'post_row_actions\', \'rd_dup