This is a very opinionated base theme for WordPress, build from several iterations of our projects' themes on production.
node_modules
to assets/vendor
/wp-content/themes/
$ npm install
build
task
$ npm run build
Or watch for changes
$ npm run watch
All static assets, like stylesheets, JavaScript files, images, icons and fonts should go in the /assets
directory. All 3rd party frameworks and plugins should go in the /assets/vendor
directory.
Feel free to use Npm for installing and updating them with the --save
flag so our gulp build:vendor
task can copy the files to the assets/vendor
directory.
SASS is strictly required in development, use Gulp to compile the CSS files. Use components, mixins and variables folders to keep organized and build modular & reusable files.
All PHP scripts that aren't templates should go in /includes
. Eg. /includes/class-theme.php
. Refer to the WordPress Coding Standards for naming convention.
Translation files should live in the /languages
directory.
node_modules
is where all Node.js packaged modules will be stored to be used in the Build process with Gulp. This directory is excluded from the Git repo by default. Keep it this way.
partials
is where all the template parts used by WordPress live.
templates
is where all user-selectable page templates live. Eg. an "About us" page /* Template Name: About Us */
templates/about-us.php
. Please do not clutter the root directory with WordPress templates.
tests
include unit testing for our main PHP and JavaScript functionality. We encourage you to write all sort of tests for your theme here, feel free to use your favorite testing framework.
wdg-wordpress-theme
├─┬ assets
│ ├── dist
│ ├── fonts
│ ├── img
│ ├── js
│ ├── sass
│ └── vendor
├── includes
│ ├── api
│ ├── cli
│ ├── fields
│ ├── shortcodes
│ ├── vendor
│ └── widgets
├── languages
├── node_modules
├── partials
├── templates
└── tests
3rd party vendor files live in /assets/vendor
, they can be either stylesheets, JavaScript, images or any kind of helper, snippet, library or framework that isn't theme related.
Use WordPress register_style
and register_script
to add them to your theme.
To use the JavaScript vendor assets within ES6 modules you can whitelist them as globals in the gulpfile.js
.
Inside the rollup
task, add your 3rd party dependencies as follows:
globals: {
bows: 'bows',
jquery: 'jQuery',
modernizr: 'Modernizr'
},
Then include them in your theme's JavaScript files, note that we use the previously provided key jquery
and not the actual global variable jQuery
. Then we alias such variable as $
to be used inside our module.
import $ from 'jquery';
$('html').addClass('js');
Learn more about ES2015 modules.
As you can see in the code above, we provide the following vendor assets by default:
Modernizr is custom built from the references within the JavaScript & CSS asset files.
There is Composer support built-in. Packages live under /includes/vendor
and are autoloaded into the theme.
Use the command line to get to the root of the repo and run the following command to install node modules, including Gulp.
$ npm install
$ npm run build
This is a set of tasks to be run in the following order:
$ npm run build:vendor
dependencies
from package.json
to the assets/vendor
directory.$ npm run build:css
$ npm run build:js
assets/js/site.js
.$ npm run watch
The watch
task will look for changes in the /assets/js and /assets/sass files and build them accordingly.
Please note that the watch task will not generate vendor files by default or on any file change. This has changed from previous versions of the theme. Please run build:vendor
yourself.
There is Browsersync support. This is not enabled, nor installed by default.
$ npm install browser-sync
Then run the Browsersync server:
$ npm run watch:sync
We encourage all developers to use CSS pre-processors and we specially like SASS, but use whatever you feel more comfortable with. Just make sure you follow our simple rules.
/assets
where all your files will live. Eg. /assets/sass
.build:css
task to compile all files without an underscore in front of the file name.# npm install --global stylelint
Install linter packages on Atom
$ apm install linter
$ apm install linter-stylelint
Select the following on linter-stylelint
Disable when no config file is found
Install ESLint globally with NPM
# npm install --global eslint
Install linter packages on Atom
$ apm install linter
$ apm install linter-eslint
Select the following on linter-eslint
Disable when no ESLint config is found (in package.json or .eslintrc)
$ composer global require wp-coding-standards/wpcs
$ composer global require squizlabs/php_codesniffer
phpcs
command$ which phpcs
It should return a hidden directory on your home directory similar to the following:
MacOS & Linux:
~/.composer/vendor/bin/phpcs
Windows:
%HOME%\AppData\Roaming\Composer\bin\phpcs
$ phpcs --config-set installed_paths ~/.composer/vendor/wp-coding-standards/wpcs
$ apm install linter
$ apm install linter-php
$ apm install linter-phpcs
We encourage you to use the following plugins for development:
Development
Administration
Debugging
We encourage you to use WordPress CLI as much as possible in your workflow, it's an incredible tool which provides an enormous amount of power. Also look at all the community packages.
Although we are very opinionated, we are open to suggestions. Please send as a message to our email hello@wdgdc.com, through our contact page, send us a GitHub issue or even better, a pull request!