我正在开发一个 wordpress 主题,我喜欢在自定义页面中添加一个 COLOR 选项,以便管理员可以更改背景颜色、文本颜色、链接颜色等。我没有安装任何插件除了“Akismet”和“mytheme”(mytheme 是我的主题名称)之外的 wordpress 目录,所有主题在自定义页面中都有该选项。 我的问题是如何在“站点标识”选项之后出现的自定义页面中添加该 COLOR 选项。 谢谢
最佳答案
读这个:
像这样的东西应该可以工作:
function mytheme_customize_register( $wp_customize ) {
//All our sections, settings, and controls will be added here
$wp_customize->add_setting( 'header_textcolor' , array(
'default' => "#000000",
'transport' => 'refresh',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'header_textcolor', array(
'label' => __( 'Header Color', 'mytheme' ),
'section' => 'colors',
) ) );
}
add_action( 'customize_register', 'mytheme_customize_register' );
function mytheme_customize_css()
{
?>
<style type="text/css">
h2 { color: #<?php echo get_theme_mod('header_textcolor', "#000000"); ?>; }
</style>
<?php
}
add_action( 'wp_head', 'mytheme_customize_css');
通过wp_head();
输出
<style type="text/css">
h1 {color:#000000;}
</style>
关于php - 如何在wordpress自定义中添加颜色选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36786520/