Blog · Gutenberg

Adding theme.json to a Classic WordPress Theme

Jun 14, 2022By Vladimir Mrkela
Share LinkedInX
Adding theme.json to a Classic WordPress Theme

Classic WordPress themes can use the block editor, but their existing styles and settings may not fully carry over to it.

Adding a theme.json file gives the theme a way to define editor options and styles alongside its traditional files.

For people who manage classic themes, this can help create a more consistent experience between the editor and the front end.

Here’s how theme.json fits into a classic theme and what to consider when adding it.

See What theme.json Can Do in a Classic Theme

A theme.json file can add block editor features to a classic WordPress theme without replacing its PHP templates. You can use it to shape the editing experience while keeping your existing theme structure.

Add block editor features to a classic WordPress theme with theme.json, while keeping your existing PHP templates and theme structure.

For example, add block editor enhancements such as a limited color palette, preset font sizes, or custom spacing options. These choices help you and other editors create pages that match your site’s design without entering custom values each time.

You can also define global style controls for text, backgrounds, links, and common blocks. Set readable defaults in the file, then adjust them as your design needs change. WordPress applies supported settings in the editor and, for some styles, on the front end.

Start with a few useful settings, test them in the editor, and expand the file only when a clear need arises.

Check WordPress and Theme Compatibility

Before adding theme.json, check that your WordPress version supports the settings you plan to use, since support varies by feature. Confirm WordPress version support against the documentation for each setting, especially if your site must work on older installations.

Check What to verify Why it matters
WordPress Minimum version Some settings need newer releases
Theme Current features Preserve existing styles
Plugins Key features Avoid conflicts
Editor Block and classic use Match your workflow

Test on a staging site before changing a live theme. Review common pages, menus, and editor screens, then run plugin compatibility testing with the plugins your site depends on. Disable plugins one at a time if a conflict appears, and note when the issue starts. Check your theme’s support policy, too, so you know which versions it must serve. Record any limits you find before moving ahead.

Create a theme.json File in Your Classic Theme

Create a theme.json file in your theme’s root folder to set its editor options.

You can define settings such as colors, fonts, and layout widths, then register editor styles so they match your theme.

Start with only the options you need, and add more as you test them.

Add the theme.json File

To add theme.json to your classic theme, create the file in the theme’s root folder, alongside files such as style.css and functions.php. Use the exact filename, including the dot, so WordPress can find it.

You can create it with a code editor or your computer’s file manager, then save it as plain text with UTF-8 encoding.

Before editing, make a backup of your theme or use a child theme, especially if the theme is live. Check that the file sits at the top level, not inside a templates, assets, or includes folder.

This placement supports Classic theme integration and lets WordPress read the file with the theme. The Theme JSON advantages include a central place for supported theme options, which you’ll add in the next step.

Don’t rename it to theme.json.txt.

Define Theme Settings

With theme.json in your theme’s root folder, you can define settings that WordPress and compatible blocks can use. Start with a small set of options, then test them in the editor before adding more.

Use this file to support your custom design and site branding without changing your theme’s templates.

  1. Set "version": 2 so WordPress can read the current settings format.
  2. Add "settings" to control options such as color palettes, font sizes, and spacing. For example, define brand colors under "color.palette".
  3. Set "styles" only when you want to apply default styles across the site. Keep settings focused on choices users can make.
  4. Save the file, open the editor, and check whether the options appear as expected. If they don’t, validate the JSON syntax and confirm your WordPress version supports the settings you chose.

Register Editor Styles

Once your theme.json settings are in place, use its "styles" section to set default colors, fonts, and other design choices in the editor. Add rules for elements such as headings, buttons, and links, or set styles for the whole site. For example, define a readable body font and a clear text color so editors can preview content accurately.

Match the editor to your theme

  1. Set font families and sizes in "styles", using values that fit your existing design.
  2. Add color choices and spacing that reflect your front-end styles.
  3. Preview a post in the editor, then adjust any settings that look different from your theme.

If you rely on a separate CSS file, Enqueue editor styles in your theme so custom rules load in the editor. Use add_editor_style() in functions.php for that purpose. Check that your CSS doesn’t conflict with theme.json. Together, these steps help you match editor fonts and keep editing previews consistent.

Set Colors, Typography, and Editor Features

Set your theme’s color palette in theme.json so you can choose consistent colors in the editor.

You can also set font families, sizes, and other typography options. Then enable or limit editor features to give users the controls your theme supports.

Define Theme Colors

Start by defining the colors your theme should use, then add them to theme.json under settings.color.palette. Choose accessible color palettes with enough contrast for text and backgrounds. Include your brand colorways, but keep the choices focused so visitors can use them consistently.

  1. Pick a small set, such as navy, cream, and a bright accent.
  2. Give each color a clear name and a readable slug, like “Ocean Blue” and ocean-blue.
  3. Add each color as an object with name, slug, and color properties. For example, set the color value to #123456.
  4. Preview the palette in the editor, then check text against each background color.

Remove colors you don’t want editors to select. A focused palette makes page designs easier to maintain and helps your theme feel consistent across posts and pages.

Configure Typography And Editor Features

With your color palette in place, configure typography and editor features in theme.json so editors can choose consistent text styles and only the controls your theme supports.

Set typography

Add font families and sizes under settings.typography. Use Fluid font scaling with minimum and maximum values to keep text readable across screen sizes. Set line height control through styles.typography.lineHeight, then check headings and body text in the editor.

Setting Example Purpose
Font family System stack Match theme fonts
Font size Fluid range Scale text smoothly
Line height 1.6 Improve readability

Limit editor controls

Set supported options to true and unsupported ones to false. For example, enable custom font sizes only if you want editors to add them. You can also define presets so your team reuses the same choices. Test changes in the block editor, then adjust any styles that look cramped or inconsistent.

Validate theme.json and Check Your Theme Styles

Before you rely on your theme.json settings, check that the file contains valid JSON and that WordPress applies the styles as you expect.

Check your file and styles

  1. Run JSON syntax validation with an editor or online checker. Confirm that quotes, commas, braces, and brackets are in the right places, and remove comments, since JSON doesn’t allow them.
  2. Save the file in your theme’s root folder, then reload the WordPress editor. Check that your typography and color options appear as intended.
  3. Preview a page on the frontend for frontend style verification. Check headings, paragraphs, buttons, and links at desktop and mobile widths.
  4. Compare the result with your theme’s CSS. WordPress may apply settings differently in the editor and on the site, so test both views before you finish.

Use a simple page with common blocks, such as a heading, paragraph, and button. That makes it easier to see whether your settings reach real content.

Fix Common theme.json Conflicts in Classic Themes

If your styles look different in the editor and on the site, a conflict between theme.json and your theme’s CSS may be the cause. Check the browser’s inspector to see which rule wins, then update or remove the older rule in your stylesheet.

Check colors and typography

  1. Compare the palette in theme.json with colors defined in your CSS. To resolve conflicting color palettes, keep one source of truth and use matching values in both places.
  2. Review font sizes, spacing, and button styles. A broad selector, such as .button, might override settings from theme.json. Narrow it to the elements your theme needs to style.

Prevent editor overrides

Use WordPress style variables, such as var(--wp--preset--color--primary), instead of hard-coded values where practical. Avoid !important, which can hide the cause.

After each change, refresh the editor and site to confirm both match.

Frequently Asked Questions

Can a Child Theme Override Its Parent Theme’s Theme.Json Settings?

Yes, you can use Child theme overrides to replace or extend your parent’s theme.json settings. WordPress merges both files, so you’ll inherit unchanged values while your child theme’s settings take precedence when they conflict.

Does Adding Theme.Json Affect a Classic Theme’s Minimum PHP Requirements?

No, adding theme.json doesn’t raise your classic theme’s minimum PHP requirements. You can maintain PHP version compatibility and legacy hosting support, provided your WordPress version and other theme code still support your target PHP release.

How Can Users Disable Editor Settings Introduced by a Theme?

Disable editor features by overriding the theme’s theme.json settings in your child theme, or filtering them with PHP. To Remove theme defined settings with theme.json, set unwanted options to false or empty arrays.

Can Plugins Provide or Modify Theme.Json Settings?

Yes—you can let a plugin add or modify editor settings, though WordPress doesn’t merge plugin theme.json files automatically. Think of plugins as paintbrushes: use filters and editor APIs to create Plugin provided editor settings and plugin specific design controls.

What Happens to Theme.Json Settings When Switching Themes?

When you switch themes, the new theme’s theme.json controls its defaults; the previous theme’s settings don’t automatically transfer. Theme setting persistence depends on where you saved changes: site-wide customizations may remain, while theme-specific styles can disappear.

Tags
  • Classic WordPress Themes
  • Editor Styles
  • theme.json

About the author

Vladimir Mrkela

Vladimir Mrkela

Senior WordPress Developer

I’m a senior WordPress developer and co-founder of Pixel Industry. I’ve spent more than 12 years building websites, custom plugins, and integrations for all kinds of projects. I enjoy working on complex architecture, solving tricky problems, and sharing what I learn along the way.

Ready to build?

Have a WordPress project that needs expert judgment?

Get a Free ConsultationTell us about your project and we will get back to you soon.