Archived topic
local fonts not showing in editor
9 replies · Started by bjbowen on June 4, 2022
Hi there! I added the Local font per the instructions here: https://docs.generatepress.com/article/adding-local-fonts/ (As I have done before without any problem)
The fonts display correctly in the Customizer and on the frontend.
But, they don't display correctly in the Editor.
I added this snippet from another support thread:
add_filter( 'generate_editor_styles', function( $editor_styles ) {
$editor_styles[] = 'wp-content/themes/generatepress/assets/css/admin/editor-style.css';
return $editor_styles;
} );
That had no effect and I'm not even sure if that's the correct editor-style.css to call.
The local fonts are Anton and Open Sans.
Hi there,
couple if options:
1. If you added your fonts @font-face CSS in the Customizer > Additional CSS then add this snippet:
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;
} );
OR
2. If you added the @font-face to a child theme style.css then you add this snippet:
add_filter( 'generate_editor_styles', function( $editor_styles ) {
$editor_styles[] = 'style.css';
return $editor_styles;
} );
Thank you. I added #2 to my functions.php in the child theme.
I Regenerated CSS in Generate Blocks.
I double checked everything I knew to check and refreshed the page a few times. Still the fonts aren't showing in the editor.
hmmmm
Ok in your functions.php you have this:
add_filter( 'generate_editor_styles', function( $editor_styles ) {
$editor_styles[] = 'wp-content/themes/generatepress/assets/css/admin/editor-style.css';
return $editor_styles;
} );
and
/* Add local fonts to the editor */
add_filter( 'generate_editor_styles', function( $editor_styles ) {
$editor_styles[] = 'fonts.css';
return $editor_styles;
} );
Remove BOTH of them.
And just add this:
add_filter( 'generate_editor_styles', function( $editor_styles ) {
$editor_styles[] = 'style.css';
return $editor_styles;
} );
That did it!
Now I'm wondering why I didn't have this problem with the last site I built. hmmm
Thank you
WP made some changes to how editor styles were loaded, particularly in the mobile / tablet previews.
The method i provided covers all that and ties up any other loose ends from WP updates.
Glad to be of help.
Hi David,
using GP with a child theme I encountered this thread's issue just yesterday and was quite irritated at first but luckily that first snippet of yours solved it right away - thanks a lot!
Glad to hear you found that of use!
Hi David,
Will I need to add this bit of code to my starter site or will this be added in a GP update?
Will I need to add this bit of code to my starter site or will this be added in a GP update?
Yes, you will need to add it if you want to load your child theme stylesheet in the editor.
No, this code won't be added to the theme as its optional and we do not know the name of the child theme stylesheet(s) the user may or may not want to load :)
In the future we will add an option to GP Premium that manages localisation of fonts for you and that will include options to load them in the editor.