1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WordPress theme.json のフォントサイズがエディターと合わないときの対処法

Last updated at Posted at 2025-08-19

wordpressのブロックテーマでオリジナルテーマを作成しようとしたときにtheme.jsonを触りました。
fontSizeで大きさを調整しようとしたときにエディターで反映しなかったのでメモとして残しておきます。

❓ 問題

theme.json に以下のようにカスタムフォントサイズを定義したとします。

theme.json
"settings": {
  "typography": {
    "fontSizes": [
      {
        "fluid": false,
        "size": "13px",
        "slug": "small"
      },
      {
        "fluid": { "max": "18px", "min": "16px" },
        "size": "18px",
        "slug": "medium"
      },
      {
        "fluid": { "max": "32px", "min": "22px" },
        "size": "32px",
        "slug": "large"
      },
      {
        "fluid": { "max": "64px", "min": "36px" },
        "size": "64px",
        "slug": "x-large"
      },
      {
        "fluid": { "max": "120px", "min": "60px" },
        "size": "120px",
        "slug": "xx-large"
      },
      {
        "fluid": { "max": "160px", "min": "80px" },
        "size": "160px",
        "slug": "xxx-large"
      }
    ]
  }
}

しかし実際にブロックエディターで選択できるサイズは次のように表示されます。

  • 小:13px
  • 中:20px
  • 大:36px
  • 特大:42px
  • xx-large:120px
  • xxx-large:160px

👉 「中」「大」「特大」が theme.json の指定と合っていません。

スクリーンショット 2025-08-20 8.43.49.png

💡原因

これは WordPress のデフォルトのフォントサイズプリセットが残っているため です。

WordPress には最初から以下のサイズが用意されています。

  • small: 13px
  • medium: 20px
  • large: 36px

x-large: 42px

theme.json に独自の fontSizes を書いても、デフォルトが上書きされるのではなく追加される ため、両方が混在してしまいます。

✅ 解決方法

theme.json で デフォルトフォントサイズを無効化 すれば、指定したサイズだけが表示されます。

theme.json
{
  "settings": {
    "typography": {
      "defaultFontSizes": false,
      "fontSizes": [
        {
          "fluid": false,
          "size": "13px",
          "slug": "small"
        },
        {
          "fluid": { "max": "18px", "min": "16px" },
          "size": "18px",
          "slug": "medium"
        },
        {
          "fluid": { "max": "32px", "min": "22px" },
          "size": "32px",
          "slug": "large"
        },
        {
          "fluid": { "max": "64px", "min": "36px" },
          "size": "64px",
          "slug": "x-large"
        },
        {
          "fluid": { "max": "120px", "min": "60px" },
          "size": "120px",
          "slug": "xx-large"
        },
        {
          "fluid": { "max": "160px", "min": "80px" },
          "size": "160px",
          "slug": "xxx-large"
        }
      ]
    }
  }
}

これでエディター上には、定義した small / medium / large / x-large / xx-large / xxx-large のみが表示され、デフォルトの「中・大・特大」は消えます。

スクリーンショット 2025-08-20 8.48.14.png

✍️ まとめ

  • theme.json にフォントサイズを設定しても、WordPress デフォルトのサイズが混ざることがある

  • settings.typography.defaultFontSizes: false を指定すれば解決できる

  • オリジナルのフォントスケールを作るなら必須の設定

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?