Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Custom Fonts Not Working

  • Hi team,
    Not sure why, but I have followed my usual process to add custom fonts, but they are not showing up. I can see them in the Customizer > Typography > System Fonts and Generate Blocks under My Custom Fonts, but they do not display in the front end? Of course I also referred to your documentation https://docs.generatepress.com/article/adding-local-fonts/ but alas they have still not been updated to assist with non-google fonts.
    I have added the Woff, woff2 and ttf files in the child theme folder in ‘fonts’ subfolder and here is the CSS I have added.

    @font-face {
      font-family: 'ds-digitalnormal';
      src:  url('https://mysite.com/wp-content/themes/generatepress_child/fonts/ds-digi-webfont.woff2') format('woff2'),
            url('https://mysite.com/wp-content/themes/generatepress_child/fonts/ds-digi-webfont.woff') format('woff'),
           url('https://mysite.com/wp-content/themes/generatepress_child/fonts/ds-digi-webfont.ttf') format('truetype');
    }
    	@font-face {
      font-family: 'ds-digitalbold';
      src:  url('https://mysite.com/wp-content/themes/generatepress_child/fonts/ds-digib-webfont.woff2') format('woff2'),
            url('https://mysite.com/wp-content/themes/generatepress_child/fonts/ds-digib-webfont.woff') format('woff'),
           url('https://mysite.com/wp-content/themes/generatepress_child/fonts/ds-digib-webfont.ttf') format('truetype');
    }
    
    	@font-face {
      font-family: 'ds-digitalbold_italic';
      src:  url('https://mysite.com/wp-content/themes/generatepress_child/fonts/ds-digit-webfont.woff2') format('woff2'),
            url('https://mysite.com/wp-content/themes/generatepress_child/fonts/ds-digit-webfont.woff') format('woff'),
           url('https://mysite.com/wp-content/themes/generatepress_child/fonts/ds-digit-webfont.ttf') format('truetype');
    }

    I also added this to the functions.php in the Child Theme;

    add_filter( 'generate_editor_styles', function( $editor_styles ) {
        $editor_styles[] = 'style.css';
    
        return $editor_styles;
    } );
    
    add_action( 'customize_controls_print_footer_scripts', function() {
    	?>
    	<script>
    		wp.hooks.addFilter(
    			'generate_font_manager_system_fonts',
    			'your/namespace',
    			( $fonts ) => [
    				{ value: 'ds-digi-webfont', label: 'ds-digi-webfont' },
    				{ value: 'ds-digib-webfont', label: 'ds-digib-webfont' },
    				{ value: 'ds-digit-webfont', label: 'ds-digit-webfont' },
    			]
    		);	
    	</script>
    	<?php
    } );
    
    add_filter(
        'generateblocks_typography_font_family_list',
        function( $fonts ) {
            $fonts[] = [
                'label' => 'My custom fonts',
                'options' => [
                    [
                        'label' => 'ds-digi-webfont',
                        'value' => 'ds-digi-webfont',
                    ],
                    [
                        'label' => 'ds-digib-webfont',
                        'value' => 'ds-digib-webfont',
                    ],
    				[
                        'label' => 'ds-digit-webfont',
                        'value' => 'ds-digit-webfont',
                    ],
                ],
            ];
    		
            return $fonts;
        }
    );

    Still the fonts do not work?

    Thanks

  • Hi there,

    This issue can sometimes be due to the font file itself. Where did you download the fonts from?

    To confirm this, you can try using a Google Font downloaded from this tool to see if it loads correctly.

  • Yes, I am aware that your fonts are not using Google Font. What I suggested is temporarily replacing your font with any Google Font to check if the font file is causing the issue. We’ve encountered a similar problem with other users where the font file itself was problematic because they sourced the fonts from somewhere else.

  • I have just added a different font and it still does not work. If I use the Google Fonts they work fine, just not any of my Custom Fonts?

  • Hi there,

    in your @font-face. Each font has its own font-family name.

    Those are:
    ds-digitalnormal
    ds-digitalbold
    ds-digitalbold_italic

    And its those names that MUST be used when setting the font in either the customizer or the block editor.

    But in your filter hooks for the editor and customizer font list, you have them set to different names ie.

    ds-digi-webfont
    ds-digib-webfont
    ds-digit-webfont

    You need to make sure the @font-face and the font lists are identical, it doesn’t matter what they are just as long as they are the same.

  • Thanks David, all working now. That was a very foolish oversight on my part there.

  • No problem, glad to be of help!

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