Site logo

Archived topic

Theme Defaults Override in Child Theme for Colour Vars

19 replies · Started by David on June 2, 2022

Viewing posts 16–20 of 20

This is an old legacy issue in the theme before we had tons of color options and separated them.

Those specific defaults are handled in the generate_option_defaults filter: https://github.com/tomusborne/generatepress/blob/3.1.3/inc/defaults.php#L54-L58

So it would be this:

add_filter( 'generate_option_defaults', function( $defaults ) {
    $defaults['background_color'] = 'var(--base)';
    $defaults['text_color'] = 'var(--grey-1)';
    $defaults['link_color'] = 'var(--grey-1)';
    $defaults['link_color_hover'] = 'grey-3';
    $defaults['link_color_visited'] = 'var(--grey-1)';

    return $defaults;
} );

The rest of the color defaults are handled in the generate_color_option_defaults filter: https://github.com/tomusborne/generatepress/blob/3.1.3/inc/defaults.php#L121

Let me know if that helps or not :)

Thanks Tom, this leads on to how I then set defaults for all the other colour options in generate_color_option_defaults. Could you also provide an example for this? And if they have been previously set, do I also have to apply the filter to option_generate_settings as I do fr the colour overrides above? Thanks!

You do it the exact same way, just with their own respective names: https://github.com/tomusborne/generatepress/blob/3.1.3/inc/defaults.php#L121

add_filter( 'generate_color_option_defaults', function( $defaults ) {
    $defaults['top_bar_background_color'] = '#fff';

    return $defaults;
} );

Yes, these filters are only for defaults when no saved value exists. If you need to overwrite the saved value, you use the option_generate_settings filter.

Hope this helps!

Thanks Tom, very much appreciated.

You're welcome :)

This archived topic is closed to new replies.