0

I've been working on a custom theme & going through the usual rollercoaster that accompanies this particular exercise. I do find it very rewarding but what I'm looking at right now is the theme's failure upon installation to enforce default colors defined. The way I have it set up is I require the inc/customizer.php file in functions, then here's an example of the controls that work but aren't loaded by default, they have to be adjusted first:

    $wp_customize->add_setting('link_colors', array(
        'default' => '#e66998',
        'sanitize_callback' => 'esc_attr',
    ));

    $wp_customize->add_control( 
    new WP_Customize_Color_Control( 
        $wp_customize, 
        'link_colors', 
        array(
        'label' => 'Body Link Colors',
        'description' => 'This will change the color of links on your pages but not the navigation menu.',
        'section' => 'background_image',
        'settings' => 'link_colors',
        'priority' => 4
    ) 
    ));

Yes, it's in the control section I intended. And here's an example of how I'm using that little bit, including customizer_style.php in the header file:

<style type="text/css">
#container a,
.widget-container a {
    color: <?php echo get_theme_mod('link_colors') ;?>;
    }
</style>

Although it displays correctly in the customizer preview, it displays the browser's default blue text on the front end on initial theme installation. Modifying the colors works & if you revert to the default in the customizer it displays as expected, just not from the beginning. What am I missing?

0

I ended up using default stylesheet rules, which I had removed along the way, and then essentially what happens is when the user modifies the colors using the customizer it overrides the stylesheet rules.

I feel like it's a bit sloppy doing it this way but it does achieve the desired result. From what I can see, though, there's no other alternative for the default rules to be enabled because as I understand it the theme customizer writes the user's values to the DB & that doesn't occur until individual settings are modified.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.