Skip to content
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.

Description

This class help you by doing the following and common tasks among projects.

  1. Remove the actions: print_emoji_detection_script and print_emoji_styles, scripts to load emojis in the front end of WP.
  2. 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).

Usage

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';

Properties of the argument

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 from WP_DEBUG if WP_DEBUG is true then the environment is development otherwise is production. You can specify the values: development or production. Based on that will load the type of assets:
  • development: it will load production.js and style.css.
  • production: it will load production-min.js and style-min.css.
  • css_version, by default is false, and here you can specify the version number for the CSS asset.
  • js_version, by default is false, and here you can specify the version number for the JS asset.
  • load_comments by default is false and accept only true or false, based on the state of this flag it will load the required js assets for the comments.
  • remove_emoji by default is true and as same as load_comments only accepts true or false based on that it will remove or not the emoji assets in the front end.

Example

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();