Created
December 4, 2014 22:07
-
-
Save mjangda/283a1abc958ae2ce5759 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
vip_register_async_script( 'twitter', 'https://platform.twitter.com/widgets.js' ); |
This file contains 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
<?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