|
<?php |
|
/* |
|
Drop In Function for your theme. |
|
Usage in the loop: ofc_social_sharing_buttons(get_the_ID()); |
|
*/ |
|
|
|
function ofc_social_sharing_buttons($id = null) { |
|
global $post; |
|
|
|
$id = ($id) ? $id : $post->ID; |
|
|
|
// Get current page URL |
|
$ofcURL = urlencode(get_permalink($id)); |
|
|
|
// Get current page title |
|
$ofcTitle = str_replace( ' ', '%20', get_the_title($id)); |
|
|
|
// Get Post Thumbnail for pinterest |
|
$ofcThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($id), 'full' ); |
|
|
|
// Construct sharing URL without using any script |
|
$twitterURL = 'https://twitter.com/intent/tweet?text='.$ofcTitle.'&url='.$ofcURL.'&'; |
|
//$twitterURL .= ';via=ofc'; |
|
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$ofcURL; |
|
//$googleURL = 'https://plus.google.com/share?url='.$ofcURL; |
|
//$bufferURL = 'https://bufferapp.com/add?url='.$ofcURL.'&text='.$ofcTitle; |
|
$whatsappURL = 'whatsapp://send?text='.$ofcTitle . ' ' . $ofcURL; |
|
//$linkedInURL = 'https://www.linkedin.com/shareArticle?mini=true&url='.$ofcURL.'&title='.$ofcTitle; |
|
|
|
// Based on popular demand added Pinterest too |
|
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$ofcURL.'&media='.$ofcThumbnail[0].'&description='.$ofcTitle; |
|
|
|
// Add sharing button at the end of page/page content |
|
$content .= '<div class="ofc-social">'; |
|
$content .= '<h5>Share On</h5>'; |
|
$content .= '<a class="btn btn-border ofc-social-link ofc-twitter mr-2 mb-1" href="'. $twitterURL .'" target="_blank"><i class="fa fa-twitter mr-1"></i> Twitter</a>'; |
|
$content .= '<a class="btn btn-border ofc-social-link ofc-facebook mr-2 mb-1" href="'.$facebookURL.'" target="_blank"><i class="fa fa-facebook mr-1"></i> Facebook</a>'; |
|
$content .= '<a class="btn btn-border ofc-social-link ofc-whatsapp d-inline-block d-sm-none mr-2 mb-1" href="'.$whatsappURL.'" target="_blank"><i class="fa fa-whatsapp mr-1"></i> WhatsApp</a>'; |
|
//$content .= '<a class="ofc-link ofc-googleplus" href="'.$googleURL.'" target="_blank">Google+</a>'; |
|
//$content .= '<a class="ofc-link ofc-buffer" href="'.$bufferURL.'" target="_blank">Buffer</a>'; |
|
//$content .= '<a class="ofc-link ofc-linkedin" href="'.$linkedInURL.'" target="_blank">LinkedIn</a>'; |
|
$content .= '<a class="btn btn-border ofc-social-link ofc-pinterest mb-1" href="'.$pinterestURL.'" data-pin-custom="true" target="_blank"><i class="fa fa-pinterest mr-1"></i> Pin It</a>'; |
|
$content .= '</div>'; |
|
|
|
echo $content; |
|
|
|
}; |