Skip to Content
Menu

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);
Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

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

    No Hooks

    This function does not have any filters or actions available. Request one?

    Note: This function contains 1 to-do comment.

    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); //@todo "Nebula" 0: Update this to use the new syntax as of WP 6.3
    
                if ( !empty($attributes) ){
                    $attributes = ( is_array($attributes) )? $attributes : array($attributes); //Make sure it is an array
                    foreach ( $attributes as $attribute ){
                        $is_data_added = wp_script_add_data($handle, $attribute, true);
                    }
                }
            }
    

    Override

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