Created
June 8, 2020 19:53
-
-
Save jbd91/4aed0aff5d324d1cd48fa5a114ac3969 to your computer and use it in GitHub Desktop.
Find Enqueued WP Script Handles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wpa54064_inspect_scripts() { | |
global $wp_scripts; | |
foreach( $wp_scripts->queue as $handle ) : | |
echo $handle; | |
endforeach; | |
} | |
add_action( 'wp_print_scripts', 'wpa54064_inspect_scripts' ); | |
// DEFER SCRIPTS WITH HANDLES FROM ABOVE | |
function mind_defer_scripts( $tag, $handle, $src ) { | |
$defer = array( | |
'wp-polyfill', | |
'marketo-forms-library', | |
'marketo-forms-activator', | |
'wedc-success-stories-activator', | |
'app-js', | |
'cost-doing-business-tool', | |
'addthis_ui_vendor', | |
'addthis_ui_app', | |
'image-map-pro-dist-js', | |
'google-jsapi', | |
'monsterinsights-frontend-script', | |
'jquery-ui-autocomplete', | |
'jqueryfusion-scripts', | |
'contact-coleman-activator', | |
'cookie-notice-front', | |
'cost-of-living-activator', | |
'admin-bar', | |
'cookie-notice-front', | |
'contact-coleman-activator', | |
'cost-of-living-activator', | |
'dwd-vet-job-search-activator', | |
'jquery-ui-autocomplete', | |
'dwd-vet-job-search-predictive-search', | |
'dwd-job-search-activator', | |
'wedc-events-activator', | |
'image-map-pro-dist-js', | |
'marketo-forms-library', | |
'marketo-forms-activator', | |
'rql-countto', | |
'regional-quality-of-life-activator', | |
'wedc-success-stories-activator', | |
'wpml-legacy-dropdown-0', | |
'monsterinsights-vue-vendors', | |
'monsterinsights-vue-common', | |
'monsterinsights-vue-frontend', | |
'slick', | |
'matchHeight', | |
'zoomapp-js', | |
'jqueryfusion-scripts', | |
'ulp', | |
'ulptabs', | |
); | |
if ( in_array( $handle, $defer ) ) { | |
return '<script src="' . $src . '" defer="defer" type="text/javascript"></script>' . "\n"; | |
} | |
return $tag; | |
} | |
add_filter( 'script_loader_tag', 'mind_defer_scripts', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment