A template with everything you need to make a modern WordPress theme.
You can generate a standalone version of this theme template via whippet
whippet generate theme --d=directory-name
This theme template is primarily made for dxw's needs, but we hope that it will be of some use to other WordPress developers. We'd love it if you want to have a play and give us your thoughts - and pull requests are gratefully received.
This theme template makes use of iguana for dependency injection and auto-registration, iguana-theme for helper functions, and iguana-extras for other little modules.
- PHP for templates lives in
templates/, everything else lives inapp/and is tested with Kahlan tests that live inspec/. - The main JavaScript file is
assets/js/main.js. It is compiled intostatic/main.min.jswith browserify somain.jsis typically just a list ofrequire()s. - The main SCSS file is
assets/scss/main.scss. It is compiled intostatic/main.min.csswith SASS somain.scssis typically just a list of@imports. - Images live in
assets/img/. They are pre-processed/minified intostatic/img/.
- Normalize.css - makes browsers render all elements more consistently
Run PHP tests:
vendor/bin/peridot spec
Run PHP linter:
vendor/bin/php-cs-fixer fix
Build JS/CSS:
npm run build
Build JS/CSS upon file modification:
npm run watch
In vanilla WordPress, you would add this to the end of functions.php:
register_post_type('abc', [ /* ... */ ]);
function my_theme_init() {
// ...
}
add_action('init', 'my_theme_init');
In an iguana-style theme, you would put this in an new file, say app/RegisterStuff.php:
<?php
namespace Theme;
class RegisterStuff implements \Dxw\Iguana\Registerable
{
public function register()
{
register_post_type('abc', [ /* ... */ ]);
add_action('init', [$this, 'init']);
}
public function init()
{
// ...
}
}
And add a line to the end of app/di.php to instantiate this class:
$registrar->addInstance(\Theme\RegisterStuff::class, new \Theme\RegisterStuff());
In vanilla WordPress you might add a helper functions to the end of functions.php like so:
function foo()
{
...
}
But with iguana, we define that in a class too, say app/HelperFunctions.php:
<?php
namespace Theme;
class HelperFunctions
{
public function __construct(\Dxw\Iguana\Theme\Helpers $helpers)
{
$helpers->registerFunction('foo', [$this, 'foo']);
}
public function foobar()
{
// ...
}
}
And then we add a line like this to app/di.php:
$registrar->addInstance(\Theme\HelperFunctions::class, new \Theme\HelperFunctions(
$registrar->getInstance(\Dxw\Iguana\Theme\Helpers::class)
));
And instead of using foo() in your template code, use h()->foo().