|
<?php |
|
|
|
// Function to handle the thumbnail request |
|
function get_the_post_thumbnail_src($img) |
|
{ |
|
return (preg_match('~\bsrc="([^"]++)"~', $img, $matches)) ? $matches[1] : ''; |
|
} |
|
|
|
function wpvkp_social_buttons($content) { |
|
global $post; |
|
if(is_singular() || is_home()){ |
|
|
|
// Get current page URL |
|
$sb_url = urlencode(get_permalink()); |
|
|
|
// Get current page title |
|
$sb_title = str_replace( ' ', '%20', get_the_title()); |
|
|
|
// Get Post Thumbnail for pinterest |
|
$sb_thumb = get_the_post_thumbnail_src(get_the_post_thumbnail()); |
|
|
|
// Construct sharing URL without using any script |
|
$twitterURL = 'https://twitter.com/intent/tweet?text='.$sb_title.'&url='.$sb_url.'&via=wpvkp'; |
|
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$sb_url; |
|
|
|
// Based on popular demand added Pinterest too |
|
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$sb_url.'&media='.$sb_thumb[0].'&description='.$sb_title; |
|
|
|
$gplusURL ='https://plus.google.com/share?url='.$sb_title.''; |
|
|
|
// Add sharing button at the end of page/page content |
|
$content .= '<div class="sb-social">'; |
|
$content .= '<a href="'. $twitterURL .'" target="_blank"><i class="sb-icon font-twitter"></i></a>'; |
|
$content .= '<a href="'.$facebookURL.'" target="_blank"><i class="sb-icon font-facebook"></i></a>'; |
|
$content .= '<a href="'.$pinterestURL.'" target="_blank"><i class="sb-icon font-pinterest"></i></a>'; |
|
$content .= '<a href="'.$gplusURL.'"><i class="sb-icon font-gplus"></i></a>'; |
|
$content .= '</div>'; |
|
|
|
return $content; |
|
}else{ |
|
// if not a post/page then don't include sharing button |
|
return $content; |
|
} |
|
}; |
|
|
|
// Enable the_content if you want to automatically show social buttons below your post. |
|
// add_filter( 'the_content', 'wpvkp_social_buttons'); |
|
|
|
// This will create a wordpress shortcode [social]. |
|
// Please it in any widget and social buttons appear their. |
|
// You will need to enabled shortcode execution in widgets. |
|
add_shortcode('social','wpvkp_social_buttons'); |