Create a gist now

Instantly share code, notes, and snippets.

Embed
<?php
vip_register_async_script( 'twitter', 'https://platform.twitter.com/widgets.js' );
<?php
function vip_register_async_script($slug, $url) {
global $vip_async_scripts;
$slug = sanitize_key( $slug );
if ( ! isset( $vip_async_scripts[ $slug ] ) ) {
$vip_async_scripts[ $slug ] = $url;
}
}
add_action( 'wp_footer', function() {
global $vip_async_scripts;
$scripts_output = '';
if ( ! empty( $vip_async_scripts ) ) {
foreach ( $vip_scripts as $script ) {
$scripts_output .= sprintf( '<script type="text/javascript" id="heavy-async-%1$s" src="%2$s" async></script>', esc_attr( $slug ), esc_url( $url ) );
}
}
echo $scripts_output;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment