[Support request] Change Default Font Sizes Programatically in Child Theme

Home Forums Support [Support request] Change Default Font Sizes Programatically in Child Theme

Home Forums Support Change Default Font Sizes Programatically in Child Theme

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
  • #2261592

    Hi, I’ve written a function in my child theme that I ‘thought’ would help me set default font sizes but it does not work : ) Can you please tell me where I’ve gone wrong…

    add_filter( ‘generate_get_default_fonts’, ‘ffdv_filtered_font_defaults’ );
    add_filter( ‘option_generate_settings’, ‘ffdv_filtered_font_defaults’ );
    function ffdv_filtered_font_defaults( $fontdefaults ) {

    $fontdefaults[‘heading_2_font_size’] = ’40’;

    return $fontdefaults;


    I’d also like a similar function to change default spacing.


    Customer Support

    Hi David,

    In the old typography settings you would need filter generate_font_option_defaults to alter the default font settings.

    Now, with the current version, you would need to alter it through Appearance > Customize > Typography.

    You’ll be able to modify the default bottom margin of texts there.

    Reference: https://docs.generatepress.com/article/dynamic-typography-overview/

    With regards to other spacing values like Header Padding, you should be able to alter it programatically with filter: generate_spacing_option_defaults

    For instance, here’s a PHP snippet:

    add_filter( 'generate_spacing_option_defaults','new_spacing_defaults' );
    	function new_spacing_defaults($defaults)
    		$defaults['header_top'] = '400';
    		return $defaults;

    Reference: https://github.com/tomusborne/generatepress/blob/adfe090929b0515cdf894f4c6b722cfe8c0790dc/inc/defaults.php#:~:text=function-,generate_spacing_get_defaults,-(%20%24filter

    You can alter this though in the Customizer as well.

    Hope this clarifies!


    Hi Fernando, thanks for this. However, I’m looking to set the fonts from within my child theme rather than through the Customizer, so am looking for the correct function. Noted re: the spacing function – this works well, thank you.

    Customer Support

    Hi there,

    why not just set them using your child theme stylesheet ?


    I can do David, I just wanted to give the customer the option to see the deftults I set and override using the Customizer if need be. Thanks!

    Customer Support

    Aside from the main.css styles, GP doesn’t load any default typography styles.
    Whereas in old GP there were defaults already set in the Customizer, the new GP does not. It only adds a typography styles if you set them, and then it just spits out the CSS.

    So stylesheet is the way to go for that.
    And you will want to load that stylesheet in the editor if you want the wysiwyg block editing experience.


    Thanks David. On that note, would you recommend just copying the contents of my child theme style.css and enqueuing as editor-styles, or are there any other tricks involved (e.g. class name changes/additions or additional breakpoints, etc) that make up a ‘good’ editor stylesheet? Thanks!

    Customer Support

    Since WP 5.8 – the block_editor_settings_all filter means you can load front end styles without the need to add the old editor selectors to your CSS.

    GP makes use of that function in our own filter:

    add_filter( 'generate_editor_styles', function( $editor_styles ) {
        $editor_styles[] = 'style.css';
        return $editor_styles;
    } );

    that will load your child theme style.css in the editor and handle the editor styles.
    So there ‘should’ be no need for a separate style sheet just for the editor 🙂


    Perfect, thanks!

    Customer Support
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.