Skip to content

Instantly share code, notes, and snippets.

@mjangda
Created December 4, 2014 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjangda/283a1abc958ae2ce5759 to your computer and use it in GitHub Desktop.
Save mjangda/283a1abc958ae2ce5759 to your computer and use it in GitHub Desktop.
<?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