// 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; $bufferURL = 'https://bufferapp.com/add?url='.$sb_url.'&text='.$sb_title; $whatsappURL = 'whatsapp://send?text='.$sb_title . ' ' . $sb_url; $linkedInURL = 'https://www.linkedin.com/shareArticle?mini=true&url='.$sb_url.'&title='.$sb_title; if(!empty($sb_thumb)) { $pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$sb_url.'&media='.$sb_thumb[0].'&description='.$sb_title; } else { $pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$sb_url.'&description='.$sb_title; } // 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 .= ''; 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');