Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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

braddalton commented May 27, 2015

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