Created
December 4, 2014 22:07
-
-
Save mjangda/283a1abc958ae2ce5759 to your computer and use it in GitHub Desktop.
Revisions
-
mjangda created this gist
Dec 4, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ <?php vip_register_async_script( 'twitter', 'https://platform.twitter.com/widgets.js' ); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ <?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; } );