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.

Replacing Block editor Typography options

  • Hi,

    I’m trying to replace the default S M L in the block editor “typography size” box.
    However I cannot get it to work for less than 6 custom sizes.

    I’m doing this via functions.php

    // removes custom font sizes
    add_theme_support(‘disable-custom-font-sizes’);
    // add my own custom sizes
    add_theme_support(‘editor-font-sizes’, array( …

    I’ve noticed that if define 6 or more custom font settings it works perfectly, eg

    custom typography sizes

    however with less that 6 WP bugs out and doesn’t display the options correctly.

    Has anyone got a workaround for when setting less that 6 typo sozes?

    Is there a better way to do this, eg theme.json? that works with GP?

    Many thanks
    Ben

  • Hi there,

    can you share the entire code snippet you’re trying ?

    Please highlight the code and click the code button before submitting.

  • following code placed in functions.php

    If I have 6 or more entries, it appears as a dropdown, any less and it tries to squeeze into a row of select buttons

    add_action( 'after_setup_theme', 'jb_custom_font_sizes' );
    
    function jb_custom_font_sizes() {
    	// removes custom font sizes
      add_theme_support('disable-custom-font-sizes');
      // add my own custom sizes 
        add_theme_support('editor-font-sizes', array(
        
    		array(
                   'name' => esc_html__( 'BodySm', ' thewebsite' ),
    				'shortName' => esc_html_x( 'bodysm', 'Font size', ' thewebsite' ),
                    'size'      => "1.6rem",
                    'slug'      => 'bodysm'
                ),
    		array(
                    'name' => esc_html__( 'BodyMd', ' thewebsite' ),
    				'shortName' => esc_html_x( 'bodymd', 'Font size', ' thewebsite' ),
                    'size'      => "2rem",
                    'slug'      => 'bodymd'
                ),
    		array(
    				'name' => esc_html__( 'BodyLg', ' thewebsite' ),
    				'shortName' => esc_html_x( 'bodylg', 'Font size', ' thewebsite' ),
                    'size'      => "2.4rem",
                    'slug'      => 'bodylg'
                ),
    			array(
                   'name' => esc_html__( 'ArrowList', ' thewebsite' ),
    				'shortName' => esc_html_x( 'ArrowList', 'Font size', ' thewebsite' ),
                    'size'      => "2.1rem",
                    'slug'      => 'ArrowList'
                ),
    		array(
                   'name' => esc_html__( 'H6', ' thewebsite' ),
    				'shortName' => esc_html_x( 'H6', 'Font size', ' thewebsite' ),
                    'size'      => "2.8rem",
                    'slug'      => 'h6'
                ),
    		array(
                   'name' => esc_html__( 'H3', ' thewebsite' ),
    				'shortName' => esc_html_x( 'H3', 'Font size', ' thewebsite' ),
                    'size'      => "4.8rem",
                    'slug'      => 'h3'
                ),
    		array(
                    'name' => esc_html__( 'H2', ' thewebsite' ),
    				'shortName' => esc_html_x( 'H2', 'Font size', ' thewebsite' ),
                    'size'      => "5.6rem",
                    'slug'      => 'h2'
                ),
    		array(
    				'name' => esc_html__( 'H1', ' thewebsite' ),
    				'shortName' => esc_html_x( 'H1', 'Font size', ' thewebsite' ),
                    'size'      => "7.2rem",
                    'slug'      => 'h1'
                )
           )  );
    }
  • Hmmm…. how odd, seems like some janky logic on WP, as it returns a completely different editor component with less than 6 items in the array.

    Might be worth asking in WP support.
    In the meantime ill ask if anyone in our dev team has a idea

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