- This topic has 9 replies, 3 voices, and was last updated 1 year, 10 months ago by David.
-
AuthorPosts
-
June 22, 2022 at 11:07 am #2261592David
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.
Thanks!
DavidJune 22, 2022 at 7:18 pm #2261833Fernando Customer SupportHi 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; }
You can alter this though in the Customizer as well.
Hope this clarifies!
June 23, 2022 at 1:31 am #2262027DavidHi 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.
June 23, 2022 at 3:37 am #2262121DavidStaffCustomer SupportHi there,
why not just set them using your child theme stylesheet ?
June 23, 2022 at 3:45 am #2262129DavidI 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!
June 23, 2022 at 4:30 am #2262158DavidStaffCustomer SupportAside 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.June 27, 2022 at 5:29 am #2265659DavidThanks 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!
June 27, 2022 at 5:38 am #2265671DavidStaffCustomer SupportSince 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 🙂June 27, 2022 at 5:47 am #2265678DavidPerfect, thanks!
June 27, 2022 at 6:03 am #2265704DavidStaffCustomer SupportYou’re welcome
-
AuthorPosts
- You must be logged in to reply to this topic.