我正在开发一个 wordpress 主题,并且在主题安装后,为定制器设置的默认值不会显示在页面上,但它们会出现在定制器中。如果我在定制器的某个字段中更改某些内容并单击发布,它会显示在网页上。有谁知道为什么?代码似乎不是问题。
定制器.php:
<?php
function photonium_customizer_register($wp_customize){
$wp_customize->add_panel('home_panel', array(
'title' => 'Front Page',
'priority' => 1,
'capability' => 'edit_theme_options',
));
$wp_customize->add_section('home_section', array(
'title' => 'Home Section',
'description' => __('Here you can custom the Front Page content. <br/> To not display some fields, leave them empty.'),
'panel' => 'home_panel',
));
$wp_customize->add_setting('main_title', array(
'default' => __('Professional Photographer'),
));
$wp_customize->add_control('main_title', array(
'label' => 'Home Main Title',
'section' => 'home_section',
'priority' => 1,
));
$wp_customize->selective_refresh->add_partial('main_title', array(
'selector' => '.main-title',
));
}
add_action( 'customize_register', 'photonium_customizer_register' );
前端页面.php:
<?php if( get_theme_mod( 'main_title') ): ?>
<p class="main-title"><?php echo get_theme_mod('main_title', 'Professional Photographer'); ?></p>
<?php endif; ?>
...