Skip to content

Instantly share code, notes, and snippets.

@robspangler
Last active October 27, 2021 19:14
Show Gist options
  • Save robspangler/7e11ec86cf8440ff5e9450d2f95f234f to your computer and use it in GitHub Desktop.
Save robspangler/7e11ec86cf8440ff5e9450d2f95f234f to your computer and use it in GitHub Desktop.
Twitter
https://twitter.com/intent/tweet?url=URL&text=TITLE
Facebook
https://www.facebook.com/sharer/sharer.php?u=URL
Pinterest
https://pinterest.com/pin/create/button/?url=URL&media=IMG&description=TITLE
LinkedIn
https://www.linkedin.com/shareArticle?mini=true&url=URL&title=TITLE
Email
mailto:?subject=TITLE&body=URL
PHP URL Encode
<?php echo urlencode($var); ?>
<?php
$social_share_title = urlencode( get_the_title() );
$social_share_url = urlencode( get_permalink() );
?>
Quick and Dirty Print()
<a href="#" onclick="window.print();return false;">
Quick and Dirty Popup
onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;"
Centered Unobstrusive Popup
// Javascript Popup
$('a.social-sharer').click(function() {
popupSetWidth = 400;
popupSetHeight = 260;
// Fixes dual-screen position Most browsers Firefox
dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX;
dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY;
popupWidth = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
popupHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
popupSystemZoom = popupWidth / window.screen.availWidth;
popupLeft = (popupWidth - popupSetWidth) / 2 / popupSystemZoom + dualScreenLeft
popupTop = (popupHeight - popupSetHeight) / 2 / popupSystemZoom + dualScreenTop
popupNewWindow = window.open($(this).attr('href'), 'Share This',
`
scrollbars=yes,
width=${popupSetWidth / popupSystemZoom},
height=${popupSetHeight / popupSystemZoom},
top=${popupTop},
left=${popupLeft}
`
)
if (window.focus) popupNewWindow.focus();
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment