Skip to content

Instantly share code, notes, and snippets.

@celticwebdesign
Last active December 21, 2015 10:36
Show Gist options
  • Save celticwebdesign/f3a8988d90cd6bd5cb81 to your computer and use it in GitHub Desktop.
Save celticwebdesign/f3a8988d90cd6bd5cb81 to your computer and use it in GitHub Desktop.
Facebook share pop-up
JS ----
$('a.share_facebook').click(function(e) {
e.preventDefault();
var url = $('a.share_facebook').data('url');
var title = $('a.share_facebook').data('title');
var descr = $('a.share_facebook').data('descr');
var image = $('#slideshow_thumbnails li.thumbnail1 img').attr('src');
var winWidth = 520;
var winHeight = 350;
var winTop = (screen.height / 2) - (winHeight / 2);
var winLeft = (screen.width / 2) - (winWidth / 2);
window.open('http://www.facebook.com/sharer.php?s=100&p[title]=' + title + '&p[summary]=' + descr + '&p[url]=' + url + '&p[images][0]=' + image, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
});
PHP & WordPress ----
echo "<li>
<a href='".of_get_option("header_social_facebook")."' class='share_facebook' data-url='".urlencode( 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] )."' data-title='".urlencode(get_the_title()." - ".get_field('cottage_long_location_name'))."' data-descr='".urlencode(get_field('cottage_introduction'))."'><i class='fa fa-facebook'></i></a>
</li>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment