Site logo

[Support request] Define a font for paragraph block via Customiser – Typography

Home Forums Support [Support request] Define a font for paragraph block via Customiser – Typography

Home Forums Support Define a font for paragraph block via Customiser – Typography

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #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”?

    #2237048
    David
    Staff
    Customer Support

    Hi 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 ?

    #2237257
    Faris

    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 🙂

    #2237303
    Fernando
    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!

    #2237723
    Faris

    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;
    } );

    Source

    #2237758
    David
    Staff
    Customer Support

    So are you setting the Typography > Body style ? And that is not correct in the editor?

    #2237877
    Faris

    Yes, exactly!

    #2237896
    David
    Staff
    Customer Support

    And you have this snippet:

    https://generatepress.com/forums/topic/define-a-font-for-paragraph-block-via-customiser-typography/#post-2237723

    Which would load styles from your child theme styles.css – do you have any conflicting styles in there ?

    #2237916
    Faris

    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;
    } );
    #2237943
    David
    Staff
    Customer Support

    Where did you add the @font-face CSS for your local font?

    If its in the Customizer > Additional CSS then you need the second snippet,

    #2237978
    Faris

    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 */
    }
    #2237990
    David
    Staff
    Customer Support

    Then 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;
    } );
    #2238002
    Faris

    As always, a wonderful support team. Worked like a charm! Thanks David, thanks Fernando!

    #2238208
    David
    Staff
    Customer Support

    Glad we could be of help!

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