Skip to Content

register_script()

Enhance wp_register_script() to allow async/defer executions.

PHP April 19, 2017

Usage

PHP
nebula()->register_script($handle, $src, $exec, $deps, $ver, $in_footer)

Parameters

$handle
(Required) (String) The unique name of the script
Default: None

$src
(Required) (String) The file URI of the script
Default: None

$exec
(Optional) (String) Async or Defer
Default: None

$deps
(Optional) (Array) Array of script dependencies
Default: None

$ver
(Optional) (String) Version number of the script
Default: false

$in_footer
(Optional) (Boolean) Whether to load the script in the footer
Default: false

Parameter Notes

All of these parameters are the exact same as wp_register_script() except with the addition of $exec.

Request or provide clarification »

Examples

PHP
nebula()->register_script('nebula-main', get_template_directory_uri() . '/assets/js/main.js', 'defer', array('nebula-bootstrap', 'jquery', 'nebula-jquery_ui'), null, true);

Source File

Located in /libs/Optimization.php on line 147.

No Hooks

This function does not have any filters or actions available. Request one?
PHP
        public function register_script($handle=null, $src=null, $attributes=array(), $deps=array(), $ver=false, $in_footer=false){
            wp_register_script($handle, $src, $deps, $ver, $in_footer);

            if ( !empty($attributes) ){
                $attributes = ( is_array($attributes) )? $attributes : array($attributes); //Make sure it is an array
                foreach ( $attributes as $attribute ){
                    wp_script_add_data($handle, $attribute, true);
                }
            }
        }

Override

This function can not be short-circuited with an override filter. Request one?