- This topic has 13 replies, 3 voices, and was last updated 3 years, 4 months ago by
David.
-
AuthorPosts
-
May 29, 2022 at 12:25 am #2236615
Faris
Hello team,
I followed Leo’s tutorial on how to add a local font and it worked nicely as usual. Just wondering, how I define a specific font (target element) via “Customiser – Typography” for the “Paragraph block”?
May 29, 2022 at 9:04 am #2237048David
StaffCustomer SupportHi there,
by default the paragraph block will receive the typography styles of the
body
element.
are you wanting to style a specific paragraph or all of them ?May 29, 2022 at 2:34 pm #2237257Faris
All of them. I just figured out that this is only happening at the editing mode but when I publish the page it is working fine, so my excuse for the inconvenience. However, if there is a way to inherit the font style into the Gutenberg editing mode, please let me know? Otherwise it is not a big deal at all 🙂
May 29, 2022 at 4:59 pm #2237303Fernando Customer Support
Hi there,
To do as such, you can try adding a PHP snippet like this:
add_filter( 'block_editor_settings_all', function( $editor_settings ) { $css = wp_get_custom_css_post()->post_content; $editor_settings['styles'][] = array( 'css' => $css ); return $editor_settings; } );
Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets
Hope this helps!
May 30, 2022 at 3:02 am #2237723Faris
Thank you Fernando! What about the next snippet code I already have, do I need to combine it with yours?
add_filter( 'generate_editor_styles', function( $editor_styles ) { $editor_styles[] = 'styles.css'; return $editor_styles; } );
May 30, 2022 at 3:24 am #2237758David
StaffCustomer SupportSo are you setting the Typography > Body style ? And that is not correct in the editor?
May 30, 2022 at 5:10 am #2237877Faris
Yes, exactly!
May 30, 2022 at 5:25 am #2237896David
StaffCustomer SupportAnd you have this snippet:
Which would load styles from your child theme styles.css – do you have any conflicting styles in there ?
May 30, 2022 at 5:43 am #2237916Faris
No conflict. (I added only the first one), I am just wondering how to get the wysiwyg experience in the editor including the font “I have chosen in the Customiser – Typography”. Should I add second code snippet to the first one, mix theme, use only one or what exactly? 🙂
First one:
add_filter( 'generate_editor_styles', function( $editor_styles ) { $editor_styles[] = 'styles.css'; return $editor_styles; } );
Second:
add_filter( 'block_editor_settings_all', function( $editor_settings ) { $css = wp_get_custom_css_post()->post_content; $editor_settings['styles'][] = array( 'css' => $css ); return $editor_settings; } );
May 30, 2022 at 6:11 am #2237943David
StaffCustomer SupportWhere did you add the @font-face CSS for your local font?
If its in the Customizer > Additional CSS then you need the second snippet,
May 30, 2022 at 6:50 am #2237978Faris
In style.css file.
/* 4- Adding (roboto-300 - latin) Font */ @font-face { font-family: 'Roboto'; font-style: normal; font-weight: 300; src: url('https://domain.com/wp-content/uploads/2022/05/roboto-v30-latin-300.eot'); /* IE9 Compat Modes */ src: local(''), url('https://domain.com/wp-content/uploads/2022/05/roboto-v30-latin-300.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('https://domain.com/wp-content/uploads/2022/05/roboto-v30-latin-300.woff2') format('woff2'), /* Super Modern Browsers */ url('https://domain.com/wp-content/uploads/2022/05/roboto-v30-latin-300.woff') format('woff'), /* Modern Browsers */ url('https://domain.com/wp-content/uploads/2022/05/roboto-v30-latin-300.ttf') format('truetype'), /* Safari, Android, iOS */ url('https://domain.com/wp-content/uploads/2022/05/roboto-v30-latin-300.svg#Roboto') format('svg'); /* Legacy iOS */ }
May 30, 2022 at 6:57 am #2237990David
StaffCustomer SupportThen you need this:
add_filter( 'generate_editor_styles', function( $editor_styles ) { $editor_styles[] = 'style.css'; // Make sure this is name of your child theme style sheet return $editor_styles; } );
May 30, 2022 at 7:08 am #2238002Faris
As always, a wonderful support team. Worked like a charm! Thanks David, thanks Fernando!
May 30, 2022 at 8:03 am #2238208David
StaffCustomer SupportGlad we could be of help!
-
AuthorPosts
- You must be logged in to reply to this topic.