Skip to content

Instantly share code, notes, and snippets.

@Willem-Siebe
Last active August 29, 2015 14:02
Show Gist options
  • Save Willem-Siebe/9f5580bbe26991e2619c to your computer and use it in GitHub Desktop.
Save Willem-Siebe/9f5580bbe26991e2619c to your computer and use it in GitHub Desktop.
Loads the Facebook JavaScript asynchronously. I add this to my WordPress right after the body tag as suggested by Facebook here: https://developers.facebook.com/docs/plugins/like-box-for-pages (Include the JavaScript SDK on your page once, ideally right after the opening <body> tag.). For some reason Facebook does not offer asynchronously loadin…
// Add Facebook Javascript to your website, see https://gist.github.com/Willem-Siebe/9f5580bbe26991e2619c.
function wsis_add_facebook_script() {
?>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.async=true; js.src = "//connect.facebook.net/nl_NL/sdk.js#xfbml=1&appId=xxxxxxxxxxxxxxxxxxxx&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<?php
}
add_action( 'wpbootstrap_before_header', 'wsis_add_facebook_script' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment