Skip to content

Instantly share code, notes, and snippets.

@nickmalcolm
Last active August 29, 2015 13:57
Show Gist options
  • Save nickmalcolm/9580338 to your computer and use it in GitHub Desktop.
Save nickmalcolm/9580338 to your computer and use it in GitHub Desktop.

Code for a Facebook Like Button

Since you have to log in to Facebook to get the html for a share / like / recommend button, here is the code. More options are at https://developers.facebook.com/docs/plugins/like-button

HTML5

Include the JavaScript SDK on your page once, ideally right after the opening tag.

<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_GB/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

Place the code for your plugin wherever you want the plugin to appear on your page.

<div class="fb-like" data-href="http://foo.bar" data-layout="button_count" data-action="recommend" data-show-faces="false" data-share="true"></div>

IFRAME

<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Ffoo.bar&amp;width&amp;layout=button_count&amp;action=recommend&amp;show_faces=false&amp;share=true&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowTransparency="true"></iframe>

Share Button

HTML5

Include the same JS as above.

 <div class="fb-share-button" data-href="http://foo.bar" data-type="button_count">
 </div>

Share does not have an IFRAME or Link implementation.

@parndt
Copy link

parndt commented Apr 10, 2014

👍

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