Skip to content

Instantly share code, notes, and snippets.

@ericakfranz
Created November 24, 2015 23:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericakfranz/181717a88c4370662c41 to your computer and use it in GitHub Desktop.
Save ericakfranz/181717a88c4370662c41 to your computer and use it in GitHub Desktop.
Easily include the Facebook SDK script, useful when adding Facebook Social Plugins to your site: https://developers.facebook.com/docs/plugins
<?php
/**
* Plugin Name: Genesis - Facebook SDK
* Plugin URI: https://fatpony.me/
* Description: Adds the Facebook SDK script just after the opening <body> tag on Genesis Framework sites.
* Version: 1.0.0
* Author: Erica Franz
* Author URI: https://fatpony.me/
* License: GPL2
*/
defined( 'ABSPATH' ) or die( 'No jellyfish!' );
add_action( 'genesis_before', 'fb_sdk_output' );
/*
* Facebook recommends adding the SDK script just after the opening <body> tag.
* Let's hook into 'genesis_before' to do this.
*/
function fb_sdk_output() {
echo '<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.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5&appId=1441666172782934";
fjs.parentNode.insertBefore(js, fjs);
}(document, "script", "facebook-jssdk"));</script>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment