axio-starter
Axio Starter (previously Aucor Starter)
đź–Ą For developer from developers:
Superior Gutenberg WordPress starter theme with modern build tools by Generaxion. 250+ hours of development over 6 years to make the greatest starting point for WordPress site.
Demo: axio.generax.io
🔌 Required plugins:
- Axio Core: Core functionality that is clever to be centrally updated.
- Advanced Custom Fields Pro: Some custom blocks use ACF. You can do without, but should remove them.
🏷 Buzz-words:
Gutenberg, Gulp, Yarn, SVG, SASS, Browsersync, a11y, l18n, Advanced Custom Fields, Polylang, Schema.org, Native lazyload, BEM, Babel, Responsive images
Table of contents
1. Directory structure
Directory
Contents
/acf-json/
automatically saved JSON versions of site specific fields from Advanced Custom Fields
/assets/
global JS, SASS, images, SVG and fonts
/bin/
shell scripts for bulk tasks/automations
/dist/
has processed, combined and optimized assets ready to be included to theme
/modules/
features that are packaged into modules like blocks, template parts, post-types
/inc/
global php files that are not part of template structure/modules
2. Setup
2.1 New site setup
Do these theme installation steps before modifying anything.
Download & Extract
- Download this repository
-
Extract into /wp-content/themes/ and rename for project like
sitename
Run setup
Run setup wizard in theme root with bash sh bin/setup.sh
Field
Meaning
Default
Site name
Name in style.css
Axio by Generaxion
Local development url
Browsersync’s mirror URL. Stored at /assets/manifest.js
https://axio-starter.local
Author name
Author in style.css
Generaxion
Author URL
Author URL in style.css
https://www.generaxion.com
Run localizator (if needed)
Theme strings are by default in English but we do support Finnish and probably Swedish in near future. If you would like to initialize strings in these languages, do the following:
-
Run
bin/localizator.sh
- Input language code
- Select to remove language packages after running
Install Axio Core
Some of the functionality of Axio by Generaxion require plugin Axio Core. The plugin is centrally updated so that sites using starter will be easier to maintain and there will be less duplicate code from project to project. Axio by Generaxion won’t have fatal errors without it, but for example localization won’t work without it.
Download Axio Core from WordPress.org or Github and activate.
Protip: If you are using composer: composer require wpackagist-plugin/axio-core
or WP-CLI: wp plugin install axio-core
.
First 15 minutes of your new site
Here’s optional next steps:
-
Go through the
/modules/
and remove any unneeded. Just throw them to trash. -
Save logo at
/assets/images/logo.svg
-
Setup colors and fonts at
/assets/styles/utils/_variables.scss
2.2 Developer setup
Every developer does this before first time working with the project.
-
Open terminal and navigate to
/wp-content/themes/sitename
-
Run
yarn install
(fetches all node packages for build tools).
Protip: If you don’t have Gulp installed locally run npm install --global gulp-cli
. If you are missing Yarn, install Yarn.
2.3 Work session setup
Do this everythime you start to work with the theme.
-
Open terminal and navigate to
/wp-content/themes/sitename
-
Run
gulp watch
to activate build process in background. You’ll get development proxy at http://localhost:3000 where changes to code will be updated automatically to browser (no need to reload). -
To quit press
ctrl
+c
Protip: You can also run just gulp
to build all the resources or just some resources with gulp styles
or gulp scripts
. Want to start the watch task but not open the Browsersync in browser? Start watch with quiet mode qulp watch -q
.
3. Components
Components are the first unique building blocks of this theme. They are an evolution of WordPress’s get_template_part()
function that aim to fix underlying issues of that function:
- Arguments: Template parts had no legitimate way to pass arguments (until WP 5.5.0).
- Returning and echoing: All components can be either echoed or HTML markup can be returned.
- Validation: Template part concept won’t encourage to validate arguments early and end up with highly nested if checks for the code. In components you can exit early and have separated backend and frontend functions to gather and sanitize data.
- Context free: You can create components to be used in blocks, templates and inside other components. It’s up to you how context aware/independent components you want to build.
3.1 Base component
Components get their power from abstract class Component that keeps in the structure and required functionality for each component. Every component inherits from this class. The component structure is loosely inspired by React component concept.
3.2 Using components
There are two basic ways to use component:
X_Teaser::render();
X_Teaser::get();
The render function prints out the HTML markup of the component and get will return it. You can pass arguments in an array like so:
X_Teaser::render(['id' => 123]);
X_Teaser::render([
'id' => 123
'hide_image' => true,
]);
All components can be interacted with the same way. It is up to the component to validate the given args and pick what to do with what argument.
3.3 Creating new components
<?php /** * Component: Componet's name * * @example * X_Components_Name::render([ * 'title' => 'Title', * 'description' => 'Descriptive text' * 'image' => 123 * ]); */ class X_Components_Name extends X_Component { public static function frontend($data) { ?> <div <?php parent::render_attributes($data['attr']); ?>> <?php if (!empty($data['image'])) : ?> <div class="components-name__image"> X_Image::render([ 'id' => $data['image'], 'size' => 'large', ]); </div> <?php endif; ?> <h3 class="components-name__title"> <?php echo $data['title'] ?> </h3> <p class="components-name__description"> <?php echo $data['description'] ?> </p> </div> <?php } public static function backend($args = []) { $default = [ // required 'title' => '', 'description' => '', // optional 'attr' => [], 'image' => '', ]; // overrides defaults with given args $args = wp_parse_args($args, $default); // validate arguments if (empty($args['title']) || empty($args['description'])) { return parent::error('Missing title or/and description'); } // set html attributes $args['attr']['class'][] = 'components-name'; // or make conditioning if (!empty($args['image'])) { $args['attr']['class'][] = 'components-name--has-image'; } // $args should be so pre-chewed that frontend can just use the data with simple empty() checks or foreach() loops return $args; } }
3.4 Validating arguments
As in example above the rendering of component starts by passing data to backend function in $args
that passes it to frontend function and renames it to $data
(just to mentally separate raw input from sanitized).
Here are your validation strategies:
-
Return error in backend:
return parent::error('What heppened');
and this error is displayed if WP_DEBUG is activated. In production without…