Customizer API how to add styles correctly

  • Unknown's avatar
    I'm using the Customizer API and have enabled the user to change the color of the text. The code I took from one site suggests using add_action('wp_head','fun') - but it doesn't look effective... How can I correctly include such css?
    
    function diwp_generate_theme_option_css(){
     
        $themeColor = get_theme_mod('diwp_theme_color');
        $header_bgcolor = get_theme_mod('diwp_header_bgcolor');
     
        if(!empty($themeColor)):
         
        ?>
        <style type="text/css" id="diwp-theme-option-css">
             
            .site-header{
                background:<?php echo $header_bgcolor; ?>;
            }
     
            a:hover{
                color: <?php echo $themeColor; ?>
            }        
     
            .search-form .search-submit{
                background: <?php echo $themeColor; ?>
            }
     
            .entry-title a:hover, .entry-title a:focus, .entry-title a:active, .page-title a:hover, .page-title a:focus, .page-title a:active {
                color: <?php echo $themeColor; ?>;
            }
         
        </style>    
     
        <?php
     
        endif;    
    }
     
    add_action( 'wp_head', 'diwp_generate_theme_option_css' );

  • Hello there,

    Many thanks for reaching out.

    Are you able to confirm the URL of the website that you need assistance with please?

    Also, to note we do not support custom development, so you may wish to open a topic over https://wordpress.org/support/forums/ for help with this script.

  • The topic ‘Customizer API how to add styles correctly’ is closed to new replies.