Php 与Wordpress API定制有关的问题

Php 与Wordpress API定制有关的问题,php,wordpress,Php,Wordpress,我正在制作我的第一个Wordpress主题,我正在学习API定制。但是我写的代码有点不对劲。发生了什么?当我加载wp admin页面时,它显示为空白 这是PHP代码 //Welcome Message Settings $wp_customize->add_setting( 'welcome_message' , array( 'default' => 'hi', )); $wp_customize->add_sect

我正在制作我的第一个Wordpress主题,我正在学习API定制。但是我写的代码有点不对劲。发生了什么?当我加载wp admin页面时,它显示为空白

这是PHP代码

//Welcome Message Settings

    $wp_customize->add_setting( 'welcome_message' , array(
        'default'     => 'hi',
    ));

        $wp_customize->add_section( 'test_welcomemessage' , array(
        'title'      => __('Welcome Message','my_test'),
        'description'   => 'Write your own Welcome Message for your visitors'
    ));

    $wp_customize->add_control( 'welcome_message', array(
        'label'      => __( 'Welcome Messagee', 'mytheme' ),
        'section'    => 'test_welcomemessage',
        'settings'   => 'welcome_message'
    )));

}
这是HTML结构

<div id="welcomecontainer"> 
<div class="welcomemessage"><?php echo get_theme_mod('welcome_message'); ?></div>
</div>
这个代码有什么问题? 感谢您

为了使用$wp_customize->。。您需要使用自定义\u寄存器挂钩:

我不确定这里的顺序是否重要,但您需要有:add\u部分,add\u设置,然后add\u控件

此外,在开发时,请确保在项目的根目录中将WP_DEBUG设置为true edit WP-config.php,并且在文件末尾您将找到此设置,以便查看所有错误,同时确保服务器设置为显示错误

add_action( 'customize_register', 'register_my_settings' );
function register_my_settings( $wp_customize ){
  $wp_customize->add_section( 'test_welcomemessage' , array(
    'title'      => __('Welcome Message','my_test'),
    'description'   => 'Write your own Welcome Message for your visitors'
  ));
}