Skip to content

Konfigurasi theme.json

Apa Itu theme.json?

theme.json adalah file konfigurasi utama untuk block theme. File ini mengontrol:

  • Layout & lebar konten
  • Palet warna
  • Tipografi
  • Pengaturan per block
  • CSS variables otomatis

Struktur Dasar

json
{
  "version": 2,
  "settings": {},
  "styles": {}
}

Layout & Lebar Konten

json
{
  "version": 2,
  "settings": {
    "layout": {
      "contentSize": "800px"
    }
  }
}
KonteksPerilaku
Full site editorMenggunakan full width secara default
Post/page editorMenggunakan contentSize (800px)

Mengizinkan Full-Width Alignment pada Block

Tambahkan di registerBlockType:

js
wp.blocks.registerBlockType("ourBlockTheme/banner", {
  title: "Banner",
  supports: {
    align: ["full"]
  },
  attributes: {
    align: { type: "string", default: "full" }
  },
  edit: EditComponent,
  save: SaveComponent
});

Palet Warna (Color Palette)

Mendefinisikan Warna

json
{
  "version": 2,
  "settings": {
    "color": {
      "palette": [
        {
          "slug": "blue",
          "color": "#0d3b66",
          "name": "Blue"
        },
        {
          "slug": "orange",
          "color": "#f4a259",
          "name": "Orange"
        },
        {
          "slug": "dark-orange",
          "color": "#bc6c25",
          "name": "Dark Orange"
        }
      ]
    }
  }
}

CSS Variables Otomatis

WordPress otomatis membuat CSS custom properties dari setiap warna:

css
/* Otomatis tersedia di seluruh theme */
var(--wp--preset--color--blue)        /* → #0d3b66 */
var(--wp--preset--color--orange)      /* → #f4a259 */
var(--wp--preset--color--dark-orange) /* → #bc6c25 */

Format: var(--wp--preset--color--{slug})


Styling Block Core

Mengatur Warna Default Button

json
{
  "styles": {
    "blocks": {
      "core/button": {
        "color": {
          "text": "var(--wp--preset--color--blue)",
          "background": "var(--wp--preset--color--orange)"
        }
      }
    }
  }
}

Pengaturan Per Block

Menonaktifkan Fitur untuk Block Tertentu

json
{
  "settings": {
    "blocks": {
      "core/button": {
        "border": {
          "color": false,
          "radius": false,
          "style": false,
          "width": false
        }
      }
    }
  }
}

Menonaktifkan Fitur Global

Tipografi

json
{
  "settings": {
    "typography": {
      "fontSizes": []
    }
  }
}

Mengosongkan fontSizes dengan array kosong menghilangkan pilihan ukuran font bawaan.

Daftar Fitur yang Bisa Dinonaktifkan

PropertiLokasi di settings
Custom colorscolor.custom: false
Default palettecolor.defaultPalette: false
Duotonecolor.duotone: []
Gradientscolor.gradients: []
Custom gradientcolor.customGradient: false
Text colorcolor.text: false
Link colorcolor.link: false
Font familiestypography.fontFamilies: []
Font styletypography.fontStyle: false
Font weighttypography.fontWeight: false

Contoh Lengkap theme.json

json
{
  "version": 2,
  "settings": {
    "layout": {
      "contentSize": "800px"
    },
    "color": {
      "palette": [
        { "slug": "blue", "color": "#0d3b66", "name": "Blue" },
        { "slug": "orange", "color": "#f4a259", "name": "Orange" },
        { "slug": "dark-orange", "color": "#bc6c25", "name": "Dark Orange" }
      ],
      "custom": false,
      "defaultPalette": false,
      "duotone": [],
      "gradients": [],
      "customGradient": false,
      "text": false,
      "link": false
    },
    "typography": {
      "fontSizes": [],
      "fontFamilies": [],
      "fontStyle": false,
      "fontWeight": false
    },
    "blocks": {
      "core/button": {
        "border": {
          "color": false,
          "radius": false,
          "style": false,
          "width": false
        }
      }
    }
  },
  "styles": {
    "blocks": {
      "core/button": {
        "color": {
          "text": "var(--wp--preset--color--blue)",
          "background": "var(--wp--preset--color--orange)"
        }
      }
    }
  }
}

Referensi

Dokumentasi lengkap: developer.wordpress.org → theme.json reference


Kesimpulan

FiturCara Pengaturan
Lebar kontensettings.layout.contentSize
Palet warnasettings.color.palette → array slug/color/name
CSS variablesOtomatis: var(--wp--preset--color--{slug})
Style per blockstyles.blocks["core/button"]
Setting per blocksettings.blocks["core/button"]
Nonaktifkan fiturSet ke false atau array kosong []