To use this file simply add this to your WordPress theme (in your includes
folder or similar) then add the following to your functions.php
file:
require_once(get_template_directory() . '/includes/class.wp-brunch.php');
class WPTheme extends WPBrunch {
public static function init() {
parent::init();
}
}
WPTheme::init();
By default, WPBrunch
will attempt to include the following:
vendor.js
- 3rd party scripts (those without npm packages) get compiled hereapp.js
- All of your application's js codevendor.css
- 3rd party styleshets (those without npm packages)app.css
- All of your application's css code
These files are all dependant on your brunch-config.js
file actually
registering these so may require some configuration if this does not match your
setup.
To add a new brunch powered stylesheet or javascript file to WordPress, use the following:
class WPTheme extends WPBrunch {
public static function init() {
parent::init();
add_action('wp_enqueue_scripts', [__CLASS__, 'style_script_includes']);
}
public static function style_script_includes() {
self::enqueue_file(
'new_styles',
PUBLIC_FOLDER . '/css/new-styles.css',
'style'
);
self::enqueue_file(
'new_js',
PUBLIC_FOLDER . '/css/new-js.css',
'script',
['in_footer' => true]
);
}
}
WPTheme::init();
Stylesheets can have additional args passed, as show on line 99
of the
WPBrunch
class file, which mirror those available in the WordPress
wp_enqueue_style
method.
Javascript files can have additional args passed as well, again, as show on
line 89
of the WPBrunch
class file, which mirror those available in the
WordPress wp_enqueue_script
method.
The WPBrunch
class also support the serving of assets locally in order to test
your WordPress theme on other devices on the same LAN in order to support
alternate device testing. This means that you can easily test the current
website's progress at time on a mobile device.
In order to do this you will need to know your local IP address:
-
Find your current local IP address: on OSX, click on the wifi symbol whilst pressing the
alt
key and use the value given forIP Address
-
On the device you wish to test on, enter the IP address followed by a colon and the port number
8080
your local server is running on. For example:192.168.0.3:8080
The site will now load on the device. It is, however, worth noting that you
might find that custom field image assets do not appear to load. This is due to
the change in IP address from the new device to that of the machine running the
PHP server. To correct this, add the following to your wp-config.php
file:
define('BRUNCH_LOCAL_ASSETS', true);
This will trigger a change within the WPBrunch
class, amending asset urls within
custom fields to be corrected in order to be server locally.
Note: This should only ever be set to true
on local development environments!