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&p[title]=<?php echo $title;?>&p[summary]=<?php echo $summary;?>&p[url]=<?php echo $url; ?>&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-------------------->
<?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&p[title]=<?php echo $title;?>&p[summary]=<?php echo $summary;?>&p[url]=<?php echo $url; ?>&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.
No comments:
Post a Comment