Last active
February 26, 2016 20:30
-
-
Save AmeliaBriscoe/157b4f2715e271074a83 to your computer and use it in GitHub Desktop.
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 characters
<?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 && (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'); | |
add('//assets.pinterest.com/js/pinit.js'); | |
}(document, 'script')); | |
</script> | |
<?php | |
} | |
add_action('genesis_before', 'add_bulk_async_sdk'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/