Skip to Content


Add defer or async to other (non-Nebula) scripts.

PHP April 26, 2017


This function runs automatically, so it is not called manually. Is this incorrect?

Source File

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

2 Hooks

Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

Need a new filter hook? Request one here.

This function has no action hooks available. Request one?

        public function defer_async_additional_scripts(){
            if ( !$this->is_admin_page(true) ){
                $to_defer = apply_filters('nebula_defer_scripts', array('jquery-migrate', 'jquery.form', 'contact-form-7', 'wp-embed')); //Allow other functions to hook in to add defer to existing scripts
                $to_async = apply_filters('nebula_async_scripts', array()); //Allow other functions to hook in to add async to existing scripts

                //Defer scripts
                if ( !empty($to_defer) && is_array($to_defer) ){
                    foreach ( $to_defer as $handle ){
                        wp_script_add_data($handle, 'defer', true);

                //Async scripts
                if ( !empty($to_async) && is_array($to_async) ){
                    foreach ( $to_async as $handle ){
                        wp_script_add_data($handle, 'async', true);


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