最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - Gutenberg - editor-font-sizes in functions not working

programmeradmin0浏览0评论

I'm adding theme support for editor-font-sizes in my functions.php but it doesn’t take affect. Any ideas why?

I’ve already added a custom color palette without issue, but having issues with this:

add_theme_support( 'editor-font-sizes', array(
    array(
        'name' => __( 'extra small', 'platetheme' ),
        'shortName' => __( 'XS', 'platetheme' ),
        'size' => 11,
        'slug' => 'small'
    ),
    array(
        'name' => __( 'regular', 'platetheme' ),
        'shortName' => __( 'M', 'platetheme' ),
        'size' => 16,
        'slug' => 'regular'
    ),
    array(
        'name' => __( 'large', 'platetheme' ),
        'shortName' => __( 'L', 'platetheme' ),
        'size' => 36,
        'slug' => 'large'
    ),
    array(
        'name' => __( 'larger', 'platetheme' ),
        'shortName' => __( 'XL', 'platetheme' ),
        'size' => 50,
        'slug' => 'larger'
    )
) );

I’ve tried to disable custom font sizes to see if that was a requirement (that code works just doesn’t help with the above)

add_theme_support('disable-custom-font-sizes');

Any idea why it isn’t working on the backend editor?

I'm adding theme support for editor-font-sizes in my functions.php but it doesn’t take affect. Any ideas why?

I’ve already added a custom color palette without issue, but having issues with this:

add_theme_support( 'editor-font-sizes', array(
    array(
        'name' => __( 'extra small', 'platetheme' ),
        'shortName' => __( 'XS', 'platetheme' ),
        'size' => 11,
        'slug' => 'small'
    ),
    array(
        'name' => __( 'regular', 'platetheme' ),
        'shortName' => __( 'M', 'platetheme' ),
        'size' => 16,
        'slug' => 'regular'
    ),
    array(
        'name' => __( 'large', 'platetheme' ),
        'shortName' => __( 'L', 'platetheme' ),
        'size' => 36,
        'slug' => 'large'
    ),
    array(
        'name' => __( 'larger', 'platetheme' ),
        'shortName' => __( 'XL', 'platetheme' ),
        'size' => 50,
        'slug' => 'larger'
    )
) );

I’ve tried to disable custom font sizes to see if that was a requirement (that code works just doesn’t help with the above)

add_theme_support('disable-custom-font-sizes');

Any idea why it isn’t working on the backend editor?

Share Improve this question asked Jan 15, 2019 at 4:58 thetwopctthetwopct 2913 silver badges12 bronze badges 2
  • did you ever solve this and how can you set this for custom post types? thanks D. – v3nt Commented Sep 18, 2019 at 17:22
  • 1 I've added my answer below, should solve it and get it working – thetwopct Commented Sep 20, 2019 at 9:07
Add a comment  | 

1 Answer 1

Reset to default 2

I believe to get this working I wasn't calling this at the correct time, and I wrapped it in a function after_setup_theme, like so:

add_action( 'after_setup_theme', 'ttp_custom_font_sizes' );

function ttp_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' => __( 'Small'),
        'size' => 12,
        'slug' => 'small'
    ),
    array(
        'name' => __( 'Normal'),
        'size' => 16,
        'slug' => 'normal'
    ),
    array(
        'name' => __( 'Large'),
        'size' => 36,
        'slug' => 'large'
    ),
    array(
        'name' => __( 'Huge'),
        'size' => 50,
        'slug' => 'huge'
    )
    ) );
}
发布评论

评论列表(0)

  1. 暂无评论