Php 如何在自定义主题中个性化Wordpress颜色?
我在网站的某个地方找到了一个代码,它完成了我需要完成的部分工作。它添加了一个单色选择器,但我尝试添加多个选择器,但找不到正确的方法Php 如何在自定义主题中个性化Wordpress颜色?,php,wordpress,wordpress-theming,themes,Php,Wordpress,Wordpress Theming,Themes,我在网站的某个地方找到了一个代码,它完成了我需要完成的部分工作。它添加了一个单色选择器,但我尝试添加多个选择器,但找不到正确的方法 function mytheme_customize_register( $wp_customize ) { //All our sections, settings, and controls will be added here $wp_customize->add_setting( 'header_textcolor' , array(
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');
函数mytheme\u自定义\u寄存器($wp\u自定义){
//我们的所有部分、设置和控件都将添加到此处
$wp\u自定义->添加\u设置('header\u textcolor',数组(
'默认值'=>“#000000”,
“传输”=>“刷新”,
) );
$wp\u customize->add\u控件(新wp\u customize\u Color\u控件($wp\u customize,'header\u textcolor',数组(
'label'=>\('Header Color','mytheme'),
'部分'=>'颜色',
) ) );
}
添加操作('customize_register'、'mytheme_customize_register');
函数mytheme_customize_css()
{
?>
h2{color:#}
嗨,我相信我晚了几个月,也许你已经解决了这个问题,但这里有一个解决方案来帮助有同样问题的人
function mytheme_customize_register( $wp_customize ) {
//All our sections, settings, and controls will be added here
$wp_customize->add_setting( 'link-color' , array(
'default' => "#000000",
'transport' => 'refresh',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link-color', array(
'label' => __( 'Link Color', 'mytheme' ),
'section' => 'colors',
) ) );
//All our sections, settings, and controls will be added here
$wp_customize->add_setting( 'link-hover' , array(
'default' => "#ffffff",
'transport' => 'refresh',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link-hover', array(
'label' => __( 'Link Hover', 'mytheme' ),
'section' => 'colors',
) ) );
}
add_action( 'customize_register', 'mytheme_customize_register' );
function mytheme_customize_css() {
?>
<style type="text/css">
/* link color style define !important if need*/
a { color: <?php echo get_theme_mod('link-color', "#000000"); ?> !important; }
/* link color hover effect style define !important if need*/
a:hover { color: <?php echo get_theme_mod('link-hover', "#ffffff"); ?> !important; }
</style>
<?php
}
add_action( 'wp_head', 'mytheme_customize_css');
函数mytheme\u自定义\u寄存器($wp\u自定义){
//我们的所有部分、设置和控件都将添加到此处
$wp_自定义->添加_设置('link color',数组(
'默认值'=>“#000000”,
“传输”=>“刷新”,
) );
$wp\u customize->add\u控件(新wp\u customize\u Color\u控件($wp\u customize,'link Color',数组(
'label'=>\('Link Color','mytheme'),
'部分'=>'颜色',
) ) );
//我们的所有部分、设置和控件都将添加到此处
$wp_自定义->添加_设置('link hover',数组(
'默认'=>“#ffffff”,
“传输”=>“刷新”,
) );
$wp\u customize->add\u控件(新wp\u customize\u Color\u控件($wp\u customize,'link hover',array(
'label'=>\('Link Hover','mytheme'),
'部分'=>'颜色',
) ) );
}
添加操作('customize_register'、'mytheme_customize_register');
函数mytheme_customize_css(){
?>
/*链接颜色样式定义!如果需要,重要*/
a{color:!important;}
/*链接颜色悬停效果样式定义!如果需要,请参见*/
a:悬停{颜色:!重要;}
function mytheme_customize_register( $wp_customize ) {
//All our sections, settings, and controls will be added here
$wp_customize->add_setting( 'link-color' , array(
'default' => "#000000",
'transport' => 'refresh',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link-color', array(
'label' => __( 'Link Color', 'mytheme' ),
'section' => 'colors',
) ) );
//All our sections, settings, and controls will be added here
$wp_customize->add_setting( 'link-hover' , array(
'default' => "#ffffff",
'transport' => 'refresh',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link-hover', array(
'label' => __( 'Link Hover', 'mytheme' ),
'section' => 'colors',
) ) );
}
add_action( 'customize_register', 'mytheme_customize_register' );
function mytheme_customize_css() {
?>
<style type="text/css">
/* link color style define !important if need*/
a { color: <?php echo get_theme_mod('link-color', "#000000"); ?> !important; }
/* link color hover effect style define !important if need*/
a:hover { color: <?php echo get_theme_mod('link-hover', "#ffffff"); ?> !important; }
</style>
<?php
}
add_action( 'wp_head', 'mytheme_customize_css');