MyBB child theme development: inheritance and overrides

amtekkie · Today

A MyStudio child theme is a theme folder whose theme.json names a parent. It holds only what it changes; on sync MyStudio merges the chain (child → parent → grandparent) into one complete MyBB theme. This page covers the inheritance rules, overriding and reverting, and the command line.

In short
  • theme.json "parent": "{slug}"; up to five levels
  • Same file name replaces; new names add; settings are never inherited
  • cli.php override / revert / files manage overrides

Folder layout

themes/{child}/                         the child theme (no PHP, like every theme)
  theme.json                            {"name": "My Forum Look", "parent": "mystudio-default", …}
  default.json                          option values that differ from the defaults
  templates/{group}/{title}.html        templates this theme replaces or adds
  css/{name}.css                        stylesheets this theme replaces or adds
  js/  images/  vendor/                 the child's own assets (optional)
inc/plugins/mystudio/themes/{child}/    the child's PHP (optional)
  hooks.php                             runs after the parent's hooks.php
  options.php                           extra or changed option definitions
  lang/{code}/*.lang.php                strings that replace or add to the parent's

Inheritance rules

ItemHow a child changes it
TemplateA file with the same title replaces the parent's (the group folder may differ); a new title adds one.
StylesheetSame file name replaces the parent's file. New stylesheets are listed in the child's stylesheets, merged with the parent's by name.
properties, supports, studio_optionsMerged key by key.
modules, color_mode, fonts, google_fontsReplace the parent's value when set; inherited otherwise.
name, version, description, parentAlways the child's own.
Options schemaThe parent's entries, with the child's added or replacing by key.
Theme settings, MyStudio OptionsNot inherited. Every theme has its own saved values.
hooks.phpEvery theme's in the chain runs, the root parent first. Use your own function names.
Language filesLoaded parent first, so the child's strings win.
js/, images/, vendor/Not inherited by path: templates name the folder they load from. To use your own script, override the template that loads it. {$mybb->ms_theme_urls['{slug}']} gives each theme's asset folder.
Image folderThe child's images/ when it has one, else the nearest parent's.

A missing parent, a loop or a chain deeper than five is refused with a clear error and listed under "Broken Themes Detected".

Override and revert

ActionEditorCommand line
Copy the parent's file into the child, then syncOverride in this themecli.php override {slug} {path}
Delete the child's copy, then syncRevert to parentcli.php revert {slug} {path}
List overrides / where files come fromDimmed files in the treecli.php files {slug} --overridden / --inherited

Keeping in step with the parent

  • Editor saves in a parent reach every child that inherits that file.
  • Syncing a theme re-syncs its children. A new template or stylesheet still needs a full sync.
  • Overridden files no longer follow the parent: compare them after parent updates.
  • When overriding, keep the parent's variables and hook points (ficons_{fid}, {$post['button_like']}, {$banner_style} …) so modules keep working.

Restyle with variables, not selectors

MyStudio Default exposes CSS variables for its components. Set those instead of re-targeting its selectors, so every variant changes together. Post buttons, for example, follow --ms-pb-radius, --ms-pb-bg, --ms-pb-border, --ms-pb-color and their hover variants; button corners follow --ms-btn-radius. Set corner defaults with "studio_options": {"radius": "sharp"} rather than forcing border-radius.

Command line

php inc/plugins/mystudio/tools/cli.php create-child mystudio-default "My Forum Look"
php inc/plugins/mystudio/tools/cli.php override my-forum-look templates/header/header.html
# edit themes/my-forum-look/templates/header/header.html, then:
php inc/plugins/mystudio/tools/cli.php sync my-forum-look
php inc/plugins/mystudio/tools/cli.php validate my-forum-look

See the MyStudio command line for every command.

Packages and deleting

Exporting a child theme packs only its own folder and records the parent; importing it needs the parent first. A theme other themes inherit from can't be deleted until its children are.

Learn from the shipped child themes

MyHacker, MyPlayer, MyConsole, MyDesire, MyWizard, MyFear, MyHolidays, MyNeon, MyGazette and MyStore each override about fifteen templates for their own forum index, thread list, posts and profiles, set studio_options and add one stylesheet. Each folder has a README describing its overrides.