PHP Developer

Showing posts with label Facebook. Show all posts
Showing posts with label Facebook. Show all posts

Sunday, 14 December 2014

Create Facebook Share Button to Share Static Data or WordPress Post Data

Create Facebook Share Button to Share Static Data or WordPress Post Data

<!----------------------  Facebook APP to share post on FACEBOOK START-------------------->
               
<?php
$post_id = get_the_ID();  //Get post id
$content = get_the_content( $post_id );  // Get content with post id
$main_content = substr($content, 0, 250);  // Get First 250 character of post content
$title = urlencode(get_the_title( $post_id ));  //Get title of post by post id
$url = urlencode(get_permalink( $post_id ));   //Get url of post
$summary = urlencode( $main_content );
$image = urlencode(wp_get_attachment_image_src(get_the_post_thumbnail( $post_id, 'thumbnail' )));  // Get Featured image of post by post id
?>
<a onClick="window.open('http://www.facebook.com/sharer.php?s=100&amp;p[title]=<?php echo $title;?>&amp;p[summary]=<?php echo $summary;?>&amp;p[url]=<?php echo $url; ?>&amp;p[images][0]=<?php echo $image;?>','sharer','toolbar=0,status=0,width=548,height=325');" href="javascript: void(0)" class="side_share_fb">SHARE ON FACEBOOK</a>

<!----------------------  Facebook APP to share post on FACEBOOK END-------------------->

NOTE : - Copy this code and only change id of post according to requirement.