Skip to content

Instantly share code, notes, and snippets.

@celticwebdesign
Created December 21, 2015 11:21
Show Gist options
  • Save celticwebdesign/f882b73eeb8cd002d769 to your computer and use it in GitHub Desktop.
Save celticwebdesign/f882b73eeb8cd002d769 to your computer and use it in GitHub Desktop.
Pinterest share pop-up
JS ----
$('a.share_pinterest').click(function(e) {
e.preventDefault();
var url = $('a.share_pinterest').data('url');
var title = $('a.share_pinterest').data('title');
var descr = $('a.share_pinterest').data('descr');
var image = $('#slideshow_thumbnails li.thumbnail1 img').attr('src');
var winWidth = 750;
var winHeight = 540;
var winTop = (screen.height / 2) - (winHeight / 2);
var winLeft = (screen.width / 2) - (winWidth / 2);
window.open(
"https://www.pinterest.com/pin/create/button/?url="+url+"&media="+image+"&description="+descr+"", "Pinterest", "width="+winWidth+",height="+winHeight+",top="+winTop+",left="+winLeft+",toolbar=0,status=0"
);
});
HTML & WordPress ----
echo "<li>
<a href='#' class='share_pinterest' 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-pinterest-p'></i></a>
</li>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment