Skip to content

Instantly share code, notes, and snippets.

@jayshreehcl
Created January 6, 2016 07:13
Show Gist options
  • Save jayshreehcl/42af0d3edbda81f7cbb4 to your computer and use it in GitHub Desktop.
Save jayshreehcl/42af0d3edbda81f7cbb4 to your computer and use it in GitHub Desktop.
/*
** http://wpvkp.com/add-social-media-sharing-buttons-to-wordpress-without-plugin/
** @blogvkp
** http://wpvkp.com/
*/
// Function to handle the thumbnail request for pinterest
function gpt_src($img)
{
return (preg_match('~\bsrc="([^"]++)"~', $img, $matches)) ? $matches[1] : '';
}
function sbwp($content) {
if(is_singular() || is_home()){
$sbwpURL = get_permalink();
$sbwpTitle = str_replace( ' ', '%20', get_the_title());
$sbwpThumbnail = gpt_src(get_the_post_thumbnail());
$twitterURL = 'https://twitter.com/intent/tweet?text='.$sbwpTitle.'&url='.$sbwpURL.'&via=sbwp';
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$sbwpURL;
$googleURL = 'https://plus.google.com/share?url='.$sbwpURL;
$bufferURL = 'https://bufferapp.com/add?url='.$sbwpURL.'&text='.$sbwpTitle;
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$sbwpURL.'&media='.$sbwpThumbnail[0].'&description='.$sbwpTitle;
$content .= '<div class="sbwp-social">';
$content .= '<h3>Show Some Love</h3> <a class="sbwp-link sbwp-twitter" href="'. $twitterURL .'" target="_blank">Twitter</a>';
$content .= '<a class="sbwp-link sbwp-facebook" href="'.$facebookURL.'" target="_blank">Facebook</a>';
$content .= '<a class="sbwp-link sbwp-googleplus" href="'.$googleURL.'" target="_blank">Google+</a>';
$content .= '<a class="sbwp-link sbwp-buffer" href="'.$bufferURL.'" target="_blank">Buffer</a>';
$content .= '<a class="sbwp-link sbwp-pinterest" href="'.$pinterestURL.'" target="_blank">Pin It</a>';
$content .= '</div>';
return $content;
}else{
return $content;
}
};
add_filter( 'the_content', 'sbwp');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment