-
Notifications
You must be signed in to change notification settings - Fork 4
Assets class
Crisoforo Gaspar Hernández edited this page Oct 12, 2015
·
2 revisions
This class allow you to load and disable some unused features form the
wp_enqueue_scripts
action.
This class help you by doing the following and common tasks among projects.
- Remove the actions:
print_emoji_detection_script
andprint_emoji_styles
, scripts to load emojis in the front end of WP. - Remove the default version of
jQuery
in the front end and loading the minified version from bower components:/bower_components/jquery/dist/jquery.min.js
(only in the front end).
As the first step this class is being loaded by the dependencies.php
file, in this line.
<?php
require LIB_DIR . '/vendors/template-tags.php';
The Theme_Assets
object accept an array than can have the following properties as argument:
-
environment
, the environment of the theme, by default uses the value fromWP_DEBUG
ifWP_DEBUG
istrue
then the environment isdevelopment
otherwise isproduction
. You can specify the values:development
orproduction
. Based on that will load the type of assets: -
development
: it will loadproduction.js
andstyle.css
. -
production
: it will loadproduction-min.js
andstyle-min.css
. -
css_version
, by default isfalse
, and here you can specify the version number for the CSS asset. -
js_version
, by default isfalse
, and here you can specify the version number for the JS asset. -
load_comments
by default isfalse
and accept onlytrue
orfalse
, based on the state of this flag it will load the requiredjs
assets for the comments. -
remove_emoji
by default istrue
and as same asload_comments
only acceptstrue
orfalse
based on that it will remove or not the emoji assets in the front end.
To usage the class you can use the follow sintaxis, and paste this code inside of the functions that is executed in the action 'after_setup_theme'.
<?php
$args = array(
'css_version' => false,
'js_version' => time(),
);
$assets = new Theme_Assets( $args );
$assets->load();