Skip to content

Instantly share code, notes, and snippets.

@svenl77
Last active September 25, 2015 19:08
Show Gist options
  • Save svenl77/970191 to your computer and use it in GitHub Desktop.
Save svenl77/970191 to your computer and use it in GitHub Desktop.
Add Facebook Like button to Wordpress posts, pages and Buddypress
<?php
// Just copy this function into your functions.php and call facebook_like() where ever you want.
// If you want to use it in page and posts or text widgets as shortcode, write [facebook_like]
function facebook_like() {
echo get_facebook_like();
}
function get_facebook_like() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
$tmp = '<iframe src="http://www.facebook.com/plugins/like.php?href='.$pageURL.'&layout=standard&show_faces=true&width=450&action=like&colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:60px"></iframe>';
return $tmp;
}
add_shortcode('facebook_like', 'get_facebook_like');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment