颜色选项主题定制器 API 无输出
Color Option Theme Customizer API no Output
我正在尝试从以下设置中获取输出,但它现在可以正常工作并显示空白。当我尝试在计划文本中 echo
时,有时它会出现在定制程序模式中。我正在使用 <?php echo get_theme_mod( 'shoplabel_color' ); ?>
来获取输出。
有没有我遗漏的东西,比如 javascript 或任何东西?
$wp_customize->add_setting('label_color',
array(
'default' => '43AC6A',
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'sanitize_callback' => 'theme_slug_sanitize_hex_color'
));
$wp_customize->add_control(
new WP_Customize_Color_Control($wp_customize, 'label_color',
array (
'settings' => 'label_color',
'section' => 'my_theme_page',
'label' => __( 'Label color', 'theme_slug' )
) ));
好的,解决了我从芯片代码复制的默认函数中的问题,所以现在我编写了新函数,它正在工作
function theme_slug_sanitize_hex_color( $color ) {
if ( '' === $color )
return '';
// 3 or 6 hex digits, or the empty string.
if ( preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) )
return $color;
return null;
}
我正在尝试从以下设置中获取输出,但它现在可以正常工作并显示空白。当我尝试在计划文本中 echo
时,有时它会出现在定制程序模式中。我正在使用 <?php echo get_theme_mod( 'shoplabel_color' ); ?>
来获取输出。
有没有我遗漏的东西,比如 javascript 或任何东西?
$wp_customize->add_setting('label_color',
array(
'default' => '43AC6A',
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'sanitize_callback' => 'theme_slug_sanitize_hex_color'
));
$wp_customize->add_control(
new WP_Customize_Color_Control($wp_customize, 'label_color',
array (
'settings' => 'label_color',
'section' => 'my_theme_page',
'label' => __( 'Label color', 'theme_slug' )
) ));
好的,解决了我从芯片代码复制的默认函数中的问题,所以现在我编写了新函数,它正在工作
function theme_slug_sanitize_hex_color( $color ) {
if ( '' === $color )
return '';
// 3 or 6 hex digits, or the empty string.
if ( preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) )
return $color;
return null;
}