Skip to content

Instantly share code, notes, and snippets.

@sachyya
Created February 5, 2017 08:33
Show Gist options
  • Save sachyya/174b7ada57e9cc8b7c9c9483cd1cad92 to your computer and use it in GitHub Desktop.
Save sachyya/174b7ada57e9cc8b7c9c9483cd1cad92 to your computer and use it in GitHub Desktop.
/***************************************************/
## Social share buttons.
/***************************************************/
function sachyya_social_sharing_buttons() {
global $post;
// Show this on post only.
// Get current page URL
$shortURL = get_permalink();
// Get current page title
$shortTitle = get_the_title();
// Construct sharing URL without using any script
$twitterURL = esc_url('http://twitter.com/share?text='.$shortTitle.'&url='.$shortURL);
$facebookURL = esc_url('https://www.facebook.com/sharer/sharer.php?u='.$shortURL);
$googleURL = esc_url('https://plus.google.com/share?url='.$shortURL);
//$bufferURL = 'https://bufferapp.com/add?url='.$shortURL.'&text='.$shortTitle;
$pinterestURL = esc_url('http://pinterest.com/pin/create/button/?url='.$shortTitle.'&media='.$post->guid.'&description='.$shortTitle);
// Add sharing button at the end of page/page content
$content = '<ul>';
$content .= '<li><a href="'.$facebookURL.'" onclick="window.open(this.href, \'facebook-share\',\'width=580,height=296\');return false;"><span class="fa fa-facebook"></span></a></li>';
$content .= '<li><a href="'. $twitterURL .'" onclick="window.open(this.href, \'twitter-share\', \'width=550,height=235\');return false;"><span class="fa fa-twitter"></span></a></li>';
$content .= '<li><a href="#" onclick="window.open(\''.$pinterestURL.'\', \'pinterest-share\', \'width=490,height=530\');return false;"><span class="fa fa-pinterest-p"></span></a></li>';
$content .= '<li><a href="'.$googleURL.'" onclick="window.open(this.href, \'google-plus-share\', \'width=490,height=530\');return false;"><span class="fa fa-google-plus"></span></a></li>';
$content .= '</ul>';
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment