Method Generator
Method Generator renders the Method Child starter with a project’s own identity — theme header, text domain, function prefix, local development URL — so a new child theme starts life without a method_child_ to find and replace. It is a small Gulp project: Nunjucks templates for the files that carry names, the Method Child repository as a submodule for everything else, and one task that copies, renders, cleans and (optionally) pushes the result.
The source is pixelwatt/method-generator, currently v2-1.0.0-beta5, which templates Method Child 1.0.0-beta5. It needs Node.js with npm, the Gulp CLI (the project uses gulp 4) and, for the push step, git. The walkthrough — from download to activating the generated theme — is in Getting Started with Method v2; this page is the reference for how the tool works and what each setting changes.
How a build works
Two inputs sit side by side in the repository. method-child/ is the Method Child repository as a git submodule, pinned to the release the generator targets; it is the un-templated reference theme. njk/ holds the templated copies of the files that contain project-specific names, under njk/assets/ in the same tree layout as the theme, plus the Nunjucks templates in njk/templates/. Running gulp build-custom runs this series:
copy-build— copiesmethod-child/**(dotfiles included) intocustom/, skipping the submodule’s.git,node_modulesandpackage-lock.json.render-custom— renders every file undernjk/assets/through Nunjucks (gulp-nunjucks-render, template pathnjk/templates,inheritExtension: truesostyle.cssstaysstyle.css) intocustom/, overwriting the copies from step 1. The environment has autoescaping off, so PHP and HTML pass through untouched, block trimming off, and the template cache disabled.clean-custom— deletescustom/.git,custom/node_modulesandcustom/package-lock.jsonif any survived the copy.push-custom— initialises a repository incustom/and pushes it, when configured (see below).build-notify— prints the Method banner and a pointer to this wiki.
custom/ and _globals.html are both gitignored: the generator never commits a project. The output is meant to leave, either through the push step or by copying custom/ into wp-content/themes/.
There is one other task, rebuild-method, which renders the same templates into method-child/ itself. It is how the reference theme is kept in step with the templates when Method Child is released — run with the default globals — and with a project _globals.html in place it would rewrite the submodule with that project’s names, so it is not part of a project build.
Templated files
Every file under njk/assets/ begins {% import '_globals.html' as globals %}{% extends "_barebones.html" %}{% block content %} … {% endblock %}. _barebones.html is a single empty block — the “layout” exists only so that globals.* is in scope — and the file body is otherwise the theme file verbatim, with {{globals.…}} where a name goes. Files that carry no names are not templated at all; they come straight from the submodule.
| Template | Becomes | What is substituted |
|---|---|---|
| style.css | style.css | The whole theme header: name, URI, description, version, license, author, author URI, tags. |
| package.json | package.json | name (the text domain), version, description, author, license. |
| gulpfile.js | gulpfile.js | The BrowserSync proxy host in serve. |
| lib/*.php (theme-setup, blocks, admin-customization, cmb2-helper-functions, cmb2-options-loader, cmb2-metaboxes, post-types-and-taxonomies) | lib/*.php | Function names (code_prefix); text domains, style handles, pattern and block category slugs (code_textdomain); the theme name in the block-category example. |
| — (copied from the submodule) | functions.php, lib/config.php, assets/, screenshot.png, .eslintrc.js, .gitignore, CHANGELOG, README.md | Nothing. These contain no project-specific names. |
// njk/assets/lib/admin-customization.php
function {{globals.code_prefix}}admin_scripts() {
wp_enqueue_style( '{{globals.code_textdomain}}-admin', get_stylesheet_directory_uri() . '/assets/css/admin.css', '', THEME_VERSION );
}
// custom/lib/admin-customization.php, with the _globals.html above
function astor_admin_scripts() {
wp_enqueue_style( 'astor-admin', get_stylesheet_directory_uri() . '/assets/css/admin.css', '', THEME_VERSION );
}
Configuration: _globals.html
Copy _globals-defaults.html to _globals.html in the same folder and edit the values. The file is a list of Nunjucks {% set name = "value" %} assignments; keep that shape, with double quotes, because the push step reads three of them with regular expressions rather than through Nunjucks. Upgrading from v2-1.0.0-beta4: the GIT Push section is new, so copy it from the defaults file into an existing _globals.html.
| Variable | Default | Where it lands |
|---|---|---|
theme_name | Method Child | Theme Name in style.css; the “{{theme_name}} Blocks” category title in the blocks.php example. |
theme_uri | https://method.wiki | Theme URI. |
theme_description | A starter child theme for building block themes with Method v2. | Description in style.css; description in package.json. |
theme_version | 1.0.0-beta5 | Version in style.css and version in package.json — what the built theme reports as THEME_VERSION. Set it to the project’s own version; it does not need to match Method Child’s. |
theme_license | GNU General Public License v2 or later | License in style.css; license in package.json. |
theme_author, theme_author_uri | Rob Clark, https://robclark.io/ | Author and Author URI; author in package.json. |
theme_tags | Block Editor, CMB2, Method v2 | Tags. |
code_textdomain | method-child | The text domain of every translation call (29 substitutions); the style handles {td}-global, {td}-admin, {td}-front; the package name; the slugs {td}-page-components and {td}-blocks in the category examples. |
code_prefix | method_child_ | The prefix of every function the theme defines (46 substitutions: {prefix}scripts, {prefix}block_assets, {prefix}load_cmb2_options …) and of the meta keys and field ids in the examples (_{prefix}example_headline). Keep the trailing underscore: templates concatenate it directly, as in {{globals.code_prefix}}scripts. |
css_prefix | method-child | Reserved for stylesheet class prefixes. No template reads it in v2-1.0.0-beta5. |
localdev_url | method-child.test | The BrowserSync proxy target in the generated gulpfile.js. |
push_custom_build | false | Turn the push step on. |
git_remote_url | "" | The remote the build is pushed to. |
git_branch | main | The branch the repository is initialised on and pushed to. |
{% set theme_name = "Astor" %}
{% set theme_uri = "https://example.com" %}
{% set theme_description = "Astor, a Method v2 child theme." %}
{% set theme_version = "1.0.0" %}
{% set theme_license = "GNU General Public License v2 or later" %}
{% set theme_author = "Rob Clark" %}
{% set theme_author_uri = "https://robclark.io/" %}
{% set theme_tags = "Block Editor, CMB2, Method v2" %}
{% set code_textdomain = "astor" %}
{% set code_prefix = "astor_" %}
{% set css_prefix = "astor" %}
{% set localdev_url = "astor.test" %}
{% set push_custom_build = true %}
{% set git_remote_url = "git@github.com:pixelwatt/astor.git" %}
{% set git_branch = "main" %}
Pushing the build to a repository
With push_custom_build set to true and git_remote_url set, push-custom runs five git commands inside custom/: git init --initial-branch=<git_branch> (git 2.28 or later), git remote add origin <git_remote_url>, git add ., git commit -m "Initial commit" and git push --set-upstream origin <git_branch>. Because clean-custom ran first there is no inherited .git to collide with. The remote has to exist already and accept the branch — an empty repository is the expected case — and authentication is whatever your git already has for that host. If either setting is missing the task prints a one-line note and the build simply stays in custom/. From there the guide’s route is to clone the new repository into wp-content/themes/.
Running it
git clone --recurse-submodules https://github.com/pixelwatt/method-generator.git
cd method-generator
npm install
cp njk/templates/_globals-defaults.html njk/templates/_globals.html
# edit njk/templates/_globals.html, then:
gulp build-custom
# the theme is in ./custom (pushed to your remote if push_custom_build is true)
Without git, download method-generator.zip from the release — the asset attached to it, not GitHub’s generated Source code archive, which leaves the method-child/ submodule folder empty and gives copy-build nothing to copy. After the build, check custom/ for anything that should not ship (the submodule’s node_modules if it had been installed, for instance), then install the theme alongside Method and activate the child, never the parent. The Getting Started with Method v2 guide covers the rest.
Versions
The v2 line is versioned after the Method Child release it templates: v2-1.0.0-betaN renders Method Child 1.0.0-betaN, with the submodule pinned to that tag. The tags before it (v1.0.8 through v1.4.4-prerelase, 2020–2024) are the Method 1.x generator, which built per-project copies of Method itself from a Method submodule — v1.0.9 is where the project was renamed from Sunrise to Method. 6e77893 removed Method as the submodule and added Method Child, and 48a6c07 is the first v2 release.
| Generator | Released | Method Child | Notes |
|---|---|---|---|
v2-1.0.0-beta5 | 2026-09-18 | 1.0.0-beta5 | Push automation, clean step, build banner; templates for Method Child beta3–beta5. |
v2-1.0.0-beta4 | 2026-07-14 | 1.0.0-beta4 | Templates for Method Child beta4. |
v2-1.0.0-beta3 | 2026-02-09 | 1.0.0-beta3 | Templates for Method Child beta3. |
v2-1.0.0-beta2 | 2025-12-22 | 1.0.0-beta2 | First v2 release. |
v1.0.8 – v1.4.4-prerelase | 2020-08-21 – 2024-02-14 | — | Method 1.x builds, from a Method submodule. |
Changelog
Commit links point at pixelwatt/method-generator.
| Version | Description |
|---|---|
| v2-1.0.0-beta5 | build-custom can push the finished build: the new push-custom task initialises a repository in custom/, commits and pushes to the remote and branch set in _globals.html, and the defaults file gained a GIT Push section (push_custom_build, git_remote_url, git_branch). rebuild-custom is now the series render-custom → clean-custom → push-custom, with clean-custom removing .git, node_modules and package-lock.json from the output; build-notify prints a completion banner; Nunjucks is configured explicitly (no autoescaping, no block trimming, no cache). The templates were brought up to Method Child 1.0.0-beta3 through beta5: theme-options.php removed, the stylesheet now front-end-only with add_editor_style() in the editor, core patterns removed, the commented examples for categories, styles, icons, social platforms, options fields and responsive embeds added with the project’s prefix and text domain, the style.css header fixed, and the defaults’ version and Theme URI updated. Readme and banner updated (36a3355, 5fc5d32, bfafe9d, 3420dee). |
| v2-1.0.0-beta4 | Updated to support Method Child 1.0.0-beta4 (4dc4259). |
| v2-1.0.0-beta3 | Changes for Method Child 1.0.0-beta3 (df49027). |
| v2-1.0.0-beta2 | First v2 release: the generator now builds Method Child themes for Method v2, with Method Child replacing Method as the submodule (6e77893, 48a6c07). Carried over from Method Generator 1.x (v1.0.8–v1.4.4-prerelase). |