Tags

, , , ,

Untitled-2
Add Social Sharing button of:
1- Google+
2- Facebook
3- Twitter
4- LinkedIn
5- Pinterest

add this code in function.php

function getsocial() {
	$title = get_the_title();
	if($title != '' && $title != undefined){
		$crunchifyURL = urlencode(get_permalink());
		$spTitle = str_replace( ' ', '%20', $title);

		$crunchifyThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
		$sitename = get_bloginfo('name');

		$twitterURL = 'https://twitter.com/intent/tweet?text='.$spTitle.'&url='.$crunchifyURL.'&via='.$sitename;
		$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$crunchifyURL;
		$googleURL = 'https://plus.google.com/share?url='.$crunchifyURL;
		$linkedInURL = 'https://www.linkedin.com/shareArticle?mini=true&url='.$crunchifyURL.'&title='.$spTitle;
		$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$crunchifyURL.'&media='.$crunchifyThumbnail[0].'&description='.$spTitle;

		$variable .= '<ul class="custom-social-share">';
		$variable .= '<li><a href="'. $twitterURL .'" target="_blank"><i class="fa fa-twitter"></i></a></li>';
		$variable .= '<li><a href="'.$facebookURL.'" target="_blank"><i class="fa fa-facebook"></i></a></li>';
		$variable .= '<li><a href="'.$googleURL.'" target="_blank"><i class="fa fa-google-plus"></i></a></li>';
		$variable .= '<li><a href="'.$linkedInURL.'" target="_blank"><i class="fa fa-linkedin"></i></a></li>';
		$variable .= '<li><a href="'.$pinterestURL.'" target="_blank"><i class="fa fa-pinterest-p"></i></a></li>';
		$variable .= '</ul>';
		return $variable;
	}
};

add this line in php file to call sharing button

<?php echo getsocial(); ?>

or you can create shortcode to call this in posts and pages

Short Code For Social Share [socialshare]

<add_shortcode('socialshare','getsocial');

in this example i am using http://fontawesome.io/ for icons

Advertisements