golamrobbani
10/25/2018 - 2:47 AM

social media share option

social media share option

function wdp_get_share_link($post_id, $type){
    switch ($type){
        case 'facebook';
            return add_query_arg([
                'u' => get_the_permalink($post_id),
                '[title]' => get_the_title($post_id),
            ],'http://www.facebook.com/sharer.php');
            break;
        case 'twitter';
            return add_query_arg([
                'url' => get_the_permalink($post_id),
                'text' => get_the_title($post_id),
            ],'http://twitter.com/share');
            break;

        case 'email';
            return add_query_arg([
                'subject' => "I wanted you to see this site&amp",
                'body' => 'body=Check out this site '.get_the_permalink($post_id),
            ],'mailto:');
            break;
    }
}

function gm_get_share_link($post_id, $type)
{
	switch ($type) {
		case 'facebook';
			return add_query_arg([
				'u'     => get_the_permalink($post_id),
				'title' => get_the_title($post_id),
			], 'http://www.facebook.com/sharer.php');
			break;
		case 'twitter';
			return add_query_arg([
				'url'  => get_the_permalink($post_id),
				'text' => get_the_title($post_id),
			], 'http://twitter.com/share');
			break;

		case 'linkedin';
			return add_query_arg([
				'url'   => get_the_permalink($post_id),
				'title' => get_the_title($post_id),
			], 'http://www.linkedin.com/shareArticle');
			break;

		case 'reddit';
			return add_query_arg([
				'url'   => get_the_permalink($post_id),
				'title' => get_the_title($post_id),
			], 'http://reddit.com/submit');
			break;

		case 'googleplus';
			return add_query_arg([
				'url' => get_the_permalink($post_id),
			], 'https://plus.google.com/share');
			break;

		case 'tumblr';
			return add_query_arg([
				'url'  => get_the_permalink($post_id),
				'name' => get_the_title($post_id),
			], 'https://www.tumblr.com/share/link');
			break;

		case 'pinterest';
			return add_query_arg([
				'media'       => wp_trim_words(get_the_post_thumbnail($post_id),20),
				'url'         => get_the_permalink($post_id),
				'description' => get_the_title($post_id),
			], 'https://pinterest.com/pin/create/bookmarklet');
			break;

		case 'vk';
			return add_query_arg([
				'url'   => get_the_permalink($post_id),
				'title' => get_the_title($post_id),
			], 'http://vk.com/share.php?');
			break;

		case 'email';
			return add_query_arg([
				'subject' => "I wanted you to see this site&amp",
				'body'    => 'body=Check out this site ' . get_the_permalink($post_id),
			], 'mailto:');
			break;
	}
}




<?php echo wdp_get_share_link( $post->ID, 'facebook' ); ?>