Skip to content

Instantly share code, notes, and snippets.

@AmeliaBriscoe
Last active February 26, 2016 20:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AmeliaBriscoe/157b4f2715e271074a83 to your computer and use it in GitHub Desktop.
Save AmeliaBriscoe/157b4f2715e271074a83 to your computer and use it in GitHub Desktop.
<?php
/**
* Adding all Asynchronous Javascripts to posts and pages
*/
function add_bulk_async_sdk() { ?>
<script>
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
add = function(url, id) {
if (doc.getElementById(id)) {return;}
js = doc.createElement(script);
js.src = url;
id &amp;&amp; (js.id = id);
fjs.parentNode.insertBefore(js, fjs);
};
// Google Analytics
add(('https:' == location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js', 'ga');
// Google+ button
add('https://apis.google.com/js/plusone.js');
// Facebook SDK
add('//connect.facebook.net/en_US/all.js', 'facebook-jssdk');
// Twitter SDK
add('//platform.twitter.com/widgets.js', 'twitter-wjs');
// Pinterest
add('//assets.pinterest.com/js/pinit.js');
}(document, 'script'));
</script>
<?php
}
add_action('genesis_before', 'add_bulk_async_sdk');
?>
@braddalton
Copy link

Hello Amelia

Shouldn't the file name for the gist be functions.php not genesis-async-php unless you want to load it as a separate file. Got a question about this on the forums http://www.studiopress.com/forums/topic/adding-third-party-asynchronous-scripts-to-genesis/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment