This is a very opinionated base theme for WordPress, build from several iterations of our projects' themes on production.
- Straightforward directory structure
- PHP classes and helper functions for your WordPress theme
- Constants for URIs and server paths
- Custom post types & Taxonomies default options and auto generated labels
- Breadcrumbs
- Attachments
- Get Average colors from images
- Get paths and urls with attachment ids
- SVG parsing and rendering with a rasterized image fallback
- Menus: Additional CSS classes and sensitive defaults
- Shortcodes:
- Classes to ease the development of shortcodes with a UI integrated with Shortcake
- String functions with Doctrine's inflector
- Autoloading of classes & Composer packages
- Vendor packages using Composer & Packagist
- Enforced linting and WordPress coding standards with PHP_CodeSniffer
- Assets structure and build tools
- CSS goodies like:
- SASS (SCSS syntax): CSS pre-processor
- Autoprefixer: Automatically prefixed vendor properties
- Bourbon & Neat: SASS & Grid library
- stylelint & CSScomb: Linting and coding standards
- JavaScript goodies like:
- Vendor modules
- Copied automatically from
node_modules
toassets/vendor
- Custom Modernizr generated from your SCSS & JS files
- Copied automatically from
- Browsersync support
- Gulp tasks to build/compile and watch for asset changes
- CSS goodies like:
- Install Node.js & WordPress on your development server
- Download the theme from our GitHub repo into your themes directory
/wp-content/themes/
- Install the theme's dependencies
$ npm install
- Run the
build
task
$ npm run build
Or watch for changes
$ npm run watch
- Enable the WordPress theme and start coding!
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.
Build process with Npm & Gulp
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:
- Compile vendor files
- In parallel compile CSS & JS files
$ npm run build:vendor
- Generate a custom built Modernizr file based on usage from the project's CSS & JS.
- Copy all
dependencies
frompackage.json
to theassets/vendor
directory.
$ npm run build:css
- Grab all Sass files without an underscore in front of the file.
- Compile SASS files.
- Autoprefixer.
- Create compiled and minified versions of all CSS files.
$ npm run build:js
- Rollup to merge all ES6 modules imported from
assets/js/site.js
. - Transpile all ES6 code into ES5 with Bublé.
- Create compiled and minified versions of all CSS files.
$ 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.
- Create a directory on
/assets
where all your files will live. Eg./assets/sass
. - Pipe the
build:css
task to compile all files without an underscore in front of the file name. - Hook up on the watch task for Gulp.
- Avoid using mixins for vendor prefixes, we are already running Autoprefixer.
- Install stylelint globally with NPM
# 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)
- Install Composer
- Install WordPress coding standards & PHP_CodeSniffer
$ composer global require wp-coding-standards/wpcs
$ composer global require squizlabs/php_codesniffer
- Find the path to your
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
- Replace "bin/phpcs" with "wp-coding-standards/wpcs" and add it to your phpcs installation
$ phpcs --config-set installed_paths ~/.composer/vendor/wp-coding-standards/wpcs
- Install the linter packages on Atom
$ apm install linter
$ apm install linter-php
$ apm install linter-phpcs
We encourage you to use the following plugins for development:
Development
- Advanced Custom Fields (Pro) for fields
- Black Studio TinyMCE Widget for a standard WordPress TinyMCE widget
- Carbon Fields as an alternative to Advanced Custom Fields
- Download Monitor for managing and versioning protected assets
- Easy WP SMTP for configuring SMTP email delivery
- Enhanced Media Library for Media Library taxonomies and mime types
- Gravity Forms for form management
- Redirection for managing redirects
- Redis Object Cache for providing an interface to redis
- Shortcake (Shortcode UI) for a shortcode user interface
- W3 Total Cache for cache management
- Yoast SEO or The SEO Framework for search engine optimization
Administration
- Admin Columns for customizing the columns in WP_List_Table
- Admin Column View for a hierarchical view of pages
- Bulk Creator for initial content creation
- Duplicate Post for duplicating content
- Google Analytics by Monster Insights for Google Analytics installation and admin user exclusion
- Jarvis for fast lookups of the admin menus
- Revisionize for creating drafts of already published content
Debugging
- Query Monitor for a debugging environment
- Rewrite Rules Inspector for testing rewrite rules
- Log Viewer for log management
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 [email protected], through our contact page, send us a GitHub issue or even better, a pull request!
- Brought to you by The Web Development Group team. @dougaxe1, @kshaner, @MikeNGarrett, @neojp
- Original directory structure was inspired by Bones.
- Grunt configuration originally inspired by YeoPress.
- If we forgot someone, please send us a pull request or a message through the issues.