On this page
Custom theme settings let site owners change parts of a theme in Ghost Admin, without touching code: a button color, a homepage layout, a hero image. You define them in the theme’s package.json, and Ghost shows them in Settings › Site › Design & branding › Theme.
What you need
- A Ghost theme you can edit, and a way to upload it to your site.
- A text editor. Basic Handlebars helps.
1. Add a setting to package.json
Settings live in package.json, under config.custom. The same config key holds posts_per_page and image_sizes (see Ghost theme structure). Each setting is a key with at least a type:
{
"config": {
"custom": {
"hero_headline": {
"type": "text",
"default": "Stories worth reading",
"group": "homepage"
}
}
}
}The key is both the label in Ghost Admin (hero_headline shows as Hero headline) and the name you use in templates. Keys must be lowercase, with no special characters, in snake_case.
Warning
Renaming a key in a new theme version is a breaking change. Ghost removes the old setting, with the value the site owner entered, and creates the new one with its default.
A theme can have 20 custom settings at most.
2. Pick the type
Ghost has five types. Each has its own rules for default:
| Type | Shows in Admin as | default |
|---|---|---|
select | A dropdown; needs options, an array of strings | Required, one of the options |
boolean | A toggle | Required, true or false |
color | A color picker | Required, a hex value such as #15171a |
image | An image uploader | Not allowed |
text | A text field | Optional |
An unknown or missing type fails theme validation, so the theme won’t upload.
3. Group and describe it
Settings fall into three groups in Ghost Admin: Site wide, Homepage and Post. Without a group, a setting is site wide. Set "group": "homepage" or "group": "post" to move it.
Add a description (under 100 characters) to tell the site owner what the setting does:
"post_feed_style": {
"type": "select",
"options": ["List", "Grid"],
"default": "List",
"group": "homepage",
"description": "The layout of the post feed on the homepage"
}To show a setting only when another one has a given value, add visibility. It takes the parent setting’s name and value, in the same filter syntax the {{#get}} helper uses:
"show_images_in_feed": {
"type": "boolean",
"default": true,
"group": "homepage",
"description": "Show thumbnails when the feed style is List",
"visibility": "post_feed_style:List"
}When the condition isn’t met, the hidden setting is null in the theme. See setting visibility (opens in a new tab) in Ghost’s docs for more.
4. Use it in your templates
Every setting is on the @custom object:
<h1 class="hero__title">{{@custom.hero_headline}}</h1>For a select, compare the value with the {{#match}} helper:
{{#match @custom.post_feed_style "Grid"}}
<div class="post-feed post-feed--grid">…</div>
{{else}}
<div class="post-feed">…</div>
{{/match}}A boolean works with {{#if}}, and a color can set a CSS variable:
<style>
:root {
--color-secondary: {{@custom.secondary_color}};
}
</style>An image is either empty or a URL. Pass it to {{img_url}} with one of the sizes in your theme’s image_sizes to get a resized version:
{{#if @custom.hero_image}}
<img src="{{img_url @custom.hero_image size="l"}}" alt="">
{{/if}}Plan for empty text
A text setting can be left blank. Put the default text in package.json, as in step 1, and only print the element when there is text:
{{#if @custom.hero_headline}}
<h1 class="hero__title">{{@custom.hero_headline}}</h1>
{{/if}}When the theme must always show something, add a fallback in the template:
<h1 class="hero__title">
{{#if @custom.hero_headline}}
{{@custom.hero_headline}}
{{else}}
{{@site.title}}
{{/if}}
</h1>5. Upload the theme and test it
Zip the theme and upload it: in Settings › Site › Theme › Change theme › Upload theme. Ghost checks package.json on upload and lists any invalid settings. Then open Settings › Site › Design & branding, choose Customize, go to the Theme tab, change your settings and check the preview.
Ghost keeps the values under the theme’s name. If they reset when you update the theme, see keep your design settings when you update a Ghost theme, or deploy the theme with GitHub Actions.
Ideas for settings
Ghost’s guidelines for theme developers (opens in a new tab) say settings are for simple visual changes with a clear effect, not for complex layout or for changing how the theme works. Some that fit:
secondary_color(color): a second brand color.default_color_scheme(select, optionsSystem,Light,Dark): the scheme a visitor sees first.post_feed_style(select, optionsList,Grid, grouphomepage): the look of the post feed.hero_image(image, grouphomepage): a background for the homepage header.sticky_header(boolean): keep the header in view while scrolling.
Skip a typography setting: Ghost has its own heading and body font picker in Settings › Site › Design & branding › Brand › Typography, which a theme supports with the --gh-font-heading and --gh-font-body CSS variables. To use your own font files, see how to add custom fonts in Ghost.
The result
Site owners now change colors, layouts and images in Settings › Site › Design & branding › Theme, and see the change in the preview before they save. Your templates read each choice from @custom, and every setting has a sensible default, so the theme looks right before anyone touches it.