This is a starting point to create a new theme template. You should not use this theme for a project as it will be updated with elements. You should, however, take a snapshot and use it to create a new theme for your project.
- Installing
- Configuration
- PHP Functions
- Theme Templates
- Project Compiling
- Naming Conventions
- File Commenting
- Notable Items
- Credits
Download _starter and change the project to reflect the name of the theme you will be developing. You'll need to do a multi-step find and replace on the name in all the templates (yes this was based off of underscores at one point).
CAUTION: Search and replace the theme name references in the order listed below to avoid naming conflicts and potential PHP errors.
- Search for
'_starter'(inside single quotations) to capture the text domain. - Search for
_starter_to capture all the function names. - Search for
_starterto capture filename references. - Search for
wp-theme-starterto capture package compiling information. - Search for
Starterto capture admin page titles.
OR
- Search for:
'_starter'and replace with:'theme-name' - Search for:
_starter_and replace with:theme_name_ - Search for:
_starterand replace with:theme-namefor asset output renaming. - Search for:
wp-theme-starterand replace with:wp-theme-theme-namefor gulp and package configurations. - Search for:
Starterand replace with:Theme Namefor admin page titles and theme name references.
Update the following:
- Clear the contents and restart the documentation and versioning for the following files as needed:
readme.mdrelease-versions.md
- Update the following information in
gulpfile.js:- Git repository URL:
project_info.package.repository.urlproject_info.package.repository.bugs.urlproject_info.theme.uri
- Author URI in
project_info.theme.author_uri - Check and update the theme information in
project_info.theme:version,name,uri,author,author_uri,description,tags
- Git repository URL:
- Rename
/languages/_starter.potto/languages/[text-domain].pot.
NOTES:
Text Domain: _starterin style.css will be updated automatically from the config settings ingulpfile.jswhen the project is compiled.
You will need to install Node (includes NPM) and Gulp to use this theme's compiling functions. Please see the individual installation documentations for installing these on your system.
Install the Gulp dependencies by opening the theme folder in the Command Line Interface (CLI) and run the following command:
$ npm install
Upon completion, you will now have the project dependencies installed in the directory node_modules.
This project's settings are controlled by the Gulp config file gulpfile.js in the root directory.
In this file is the project_info, config, and paths variable objects. These objects control and sets the version, paths and asset relation information when compiling.
The CSS, JS, and sprite filenames are generated automatically from the Gulp build process using the value project_info.assets.filename_base.
NOTE: You do not need to edit below section 2.1 of gulpfile.js unless adding additional functions/dependencies or changing output settings in config.
project_info.packagesets the following information for the package manager file inpackage.json:- Package Information:
name,version,description,author,license - Repository Information:
repository.type,repository.url - Bugs URL:
bugs.url - Asset Paths Information:
css,images,js.amdin,js.lib,js.vendor
- Package Information:
package_info.themesets the stylesheet theme information instyle.cssfrom the template inassets-source/templates/tpl-style.css.
- Sets the following variables in
assets-source/sass/variables/config.scss:$version__projectfor sprite image version reference.$path__assets-basefor sprite image path reference.$filename__assets-basefor sprite filename creation.
- Sets the php information:
- Project version from
project_info.theme.version - Asset paths for
css,js/lib,js/vendor,js/admin.
- Project version from
- Core elements exist in the
functions.phpfile - Optional elements (including common) reside in the
/incfolder and can be commented out to remove.
Theme templates should be created under the /page-templates according to WordPress Theme Organization standards.
If you want to have a custom sidebar for the page template type, add the sidebar information to the the _starter_widgets_init function's $sidebars array:
$sidebars = array(
array(
'name' => 'Name',
'slug' => 'template-name',
'description' => 'Items placed here will appear in the sidebar on pages assigned to the page template page [template-name].',
),
NOTE: Be sure to update the theme version appropriately using Semantic Versioning in gulpfile.js under project_info.theme.version before compiling.
When you are ready to compile your project, open the project folder in the CLI and run the following command:
$ gulp
This will compile the Javascript, Images, CSS, and set the Theme Information.
If you want to see your changes while working, open the project folder in the CLI and run the following command:
$ gulp watch
NOTE: This will only change js, css, and images assets. You will need to run $ gulp to fully compile the project for changes to the version, language support, theme information, or updates to the paths information.
Javascript files can be found in assets-source/js and have three sub directories for script types of Library: lib, Vendor: vendor, and Admin: admin.
The lib files will compile automatically and be renamed to the value in the gulpfile.js under project_info.assets.filename_base.
The admin and vendor scripts are only compiled to their respective destination directories and are not auto loaded to the theme output. This is intended to use the functions.php file to load the scripts with wp_enqueue_script and allow for the use of dependency scripts.
Javascript files in assets-source/js/lib will run jshint on the files, concatenate, minify and rename into a single file assets/js/lib/[paths.js.output.basename].min.js.
NOTE: paths.js.output.basename maps to project_info.assets.filename_base.
These are third party scripts maintained by other developers/organizations.
Javascript files in assets-source/js/vendor will run jshint on the file and compile to assets/js/vendor.
These files will not run jshint or be concatenated or minified.
As of Version 3.3.0, Modernizr can be included in the build of the Vendor scripts. The settings for these are under config.modernizr.
| Configuration | Type | Default | Option |
|---|---|---|---|
config.modernizr.include |
boolean |
false |
Option to include the modernizr file in your project. If true, uses wp_enqueue_script to load the script and adds modernizr as a dependency for the primary theme script. |
config.modernizr.in_footer |
boolean |
true |
Sets the option to load modernizr in the footer. Default false enqueues the script just before the closing </html>. |
config.modernizr.filename |
string |
modernizr.js |
The filename to be used. |
config.modernizr.settings |
array |
See Modernizr Options for options and the tests using the browser features. |
Default options:
NOTE: Any options with underscores like _domPrefixes need to be added to the options list without the underscore:
modernizr: {
settings: {
'options': [
'_domPrefixes' // will not work
'domPrefixes' // works
]
}
}
Default settings:
svg
The options for the output can be found at Modernizr Options and the full documentation at Modernizr. The config.modernizr values for options are from the Options section and the tests are from the Browser Features.
These are intended to be individual scripts for WP-Admin.
Javascript files in assets-source/js/admin will run jshint on the file and compile to assets/js/admin.
These files will not run jshint or be concatenated or minified.
This theme uses SASS to compile one stylesheet with compression and uses Gulp for compiling. Feel free to modify and import the individual elements as needed.
Currently, this theme is simplified in it's structure to allow customization to be added, rather than stripped out / overridden. However, there are some example elements in the files than illustrate how to build the theme.
All stylesheets compiled will use an auto prefix generator based on the project settings under config.autorprefixer.
CSS Maps will be compiled per stylesheet in assets/css/maps/[filename].css.map.
The theme's stylesheet SCSS file /assets-source/sass/theme-stylesheet.scss will be compiled and renamed to the value in project_info.assets.filename_base.
- Sass for compiling CSS
- Sass-Heading-Sizes is available for percentage or fixed interval heading sizes
There are some additional mixins included:
- align-horizontal
- align-vertical
- asset-url-helpers
- center-block
- clearfix-after
- clearfix
- fill-absolute
- font-size
- font-style
- media-queries
- Sass-Heading-Sizes
- heading-decrement
- heading-decrement-fixed
- heading-increment
- heading-increment-fixed
Use the SCSS base stylesheet /assets-source/sass/rtl.scss to set styles to support additional languages in right-to-left format.
The theme's RTL SCSS file /assets-source/sass/rtl.scss will be compiled and output to the theme's root directory.
NOTE: rtl.css will compile to the theme root ./ for WordPress support.
Other SCSS files without an underscore _ prefix in assets-source/sass/ will be compiled to assets/css/[filename].css.
These stylesheets are only compiled to their respective destination directories and are not auto loaded to the theme output. This is intended to use the functions.php file to load the scripts with wp_enqueue_style and allow for the use of dependency requirements.
Images are optimized based on project settings in config.images.minification. They will be optimized and moved from assets-source/images/ to assets/images/ and will retain their directory.
SVGs in assets-source/images/sprite will be optimized, combined, and created into a sprite in assets/images.
Associative classes will be created in the SCSS files and compiled for usage as CSS classes in the format .icon-[filename]{} and .icon-only-[filename]{}. These classes will display in the TinyMCE editor in the WP Admin content section under the Formats dropdown as separate Icon and Icon Only lists. They will insert the icon with a span tag to allow editors to add the icon to content easily without remembering classes.
NOTE: The sprite filename is generated automatically from the value project_info.assets.filename_base.
Any SVG files in assets-source/images will have a copy converted and saved to a PNG format in assets/images.
SASS variables use a BEM format that is structured in the .scss-lint.yml config settings. The structure for these elements is as follows:
[block]__[element][--modifier][--state]
Using HTML elements and CSS Selectors:
[html-element]__[css-attribute][--modifier][--state]
Construct
[html-element]__[css-attribute][--modifier][--state]
Examples
$input__background-color
$input__background-color--hover
Construct
[html-element]__[css-attribute][--modifier][--state]
Examples
$link__font-color--primary
$link__font-color--primary--hover
// Single line comments.
/**
* Multi-line commenting for explanations
* and doc blocks.
*/
Examples
/**
* [foo description]
*
* @author l. hamilton
* @version [version]
* @param [type] $var [description]
* @return [type]
*/
function foo ($x) {
// Single comment.
return;
}
If you create a template without a sidebar (get_sidebar();), be sure to wrap the skip to link in header.php with a conditional statement removing the link from output. For example, if you remove get_sidebar from 404.php:
if ( ! is_404() ) {
<a class="skip-link screen-reader-text" href="#secondary"><?php esc_html_e( 'Skip to secondary content', '_starter' ); ?></a>
}
Theme base: underscores
Theme modifications, construct and build: troutacular
Mixins: See individual mixins.
Functions: See individual functions.