[Resolved] local fonts not showing in editor

Home Forums Support [Resolved] local fonts not showing in editor

Home Forums Support local fonts not showing in editor

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2243165
    bjbowen

    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.

    #2243509
    David
    Staff
    Customer Support

    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;
    } );
    #2244883
    bjbowen

    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

    #2244897
    David
    Staff
    Customer Support

    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;
    } );
    #2244900
    bjbowen

    That did it!

    Now I’m wondering why I didn’t have this problem with the last site I built. hmmm

    Thank you

    #2244919
    David
    Staff
    Customer Support

    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.

    #2409535
    Peter

    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!

    #2409787
    David
    Staff
    Customer Support

    Glad to hear you found that of use!

    #2411084
    bjbowen

    Hi David,

    Will I need to add this bit of code to my starter site or will this be added in a GP update?

    #2411145
    David
    Staff
    Customer Support

    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.

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