Try these codes to your Functions.php
We add the customizer setting.
function theme_customize_register( $wp_customize ) { $wp_customize->add_setting( 'main_color', array( 'default' => '#ffffff', 'transport' => 'refresh', 'sanitize_callback' => 'sanitize_hex_color', ) ); add_action( 'customize_register', 'theme_customize_register' );
It then integrates the customizer and attribute in CSS file.
function theme_get_customizer_css() { ob_start(); $main_color = get_theme_mod( 'main_color', '' ); if ( ! empty( $main_color ) ) { ?> .contentDetails a { color: ; } <?php } $css = ob_get_clean(); return $css; }
We add the details of customizer setting.
function theme_customize_register( $wp_customize ) {
$wp_customize->add_setting( 'main_color', array(
'default' => '#ffffff',
'transport' => 'refresh',
'sanitize_callback' => 'sanitize_hex_color',
) );
add_action( 'customize_register', 'theme_customize_register' );
It then integrates the customizer and attribute in CSS file.
function theme_get_customizer_css() {
ob_start();
$main_color = get_theme_mod( 'main_color', '' );
if ( ! empty( $main_color ) ) {
?>
.contentDetails a {
color: <?php echo $main_color; ?>;
}
<?php
}
$css = ob_get_clean();
return $css;
}
And for CSS and the customizer connection.
function theme_enqueue_styles() {
wp_enqueue_style( 'theme-styles', get_stylesheet_uri() );
$custom_css = theme_get_customizer_css();
wp_add_inline_style( 'theme-styles', $custom_css );
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );