Posts Tagged ‘share button’

These days social media is one of the main concern to increase website traffic or to popular once website. Facebook provides  sharing and like button  that can be embeded into any website or CMS with ease, It is good to let your visitors share content on your blog using their Facebook profile. It is  easy to use –  copying this snippet of code into your website and enjoy.

1. For WordPress

If you need to share your each blog  post to facebook, then simply copy and past the below code inside the while loop responsible for displaying all your blog posts or if you are displaying posts from one category.
<?php if(have_posts()):
while(have_posts()): the_post();
the_title();
the_content();
?>
<a href=”http://www.facebook.com/sharer.php?u=&lt;?php the_permalink();?>&t=<?php the_title(); ?>” title=”Facebook share button” target=”blank”>Share on Facebook</a>
<?php
endwhile;
endif;
?>

2. To embed into any website.

<?php
$current_url =”http://mywebsite.com&#8221;;
$current_title = “my custom title”;
?>
<a href=”http://www.facebook.com/sharer.php?u=&lt;?php echo $current_url; ?>&t=<?php echo $current_title; ?>” title=”Facebook share button” target=”blank”>Share on Facebook</a>

Note: To  pass custom parameters to a Facebook – Share button.

The default code script for Facebook share buttton,  Most of the time we need to pass our custom link and title. But this code does not work as expected. When share link is clicked the link from “u” parameter is passed but not the title from “t” parameter.
But  facebook actually uses standard content title, description, and images from meta-tags from the page that is going to shared.
The default code with stanadard paramertes “u” and “t”;

<a title=”Share this post/page title”
href=”http://www.facebook.com/sharer.php? u=http://mywebisite.com/mypage.php &t=my custom title”
target=”_blank”>
<img src=”path to image use as a link”
alt=”Share on Facebook” />
</a>
But we need different titles and descriptions for each post/page that is  going to be shared.
Here is a way that tells facebook what url, title and images to description to use for share button.

<a title=”Share this post/page”
href=”http://www.facebook.com/sharer.php?
s=100
&p[url]=url to share post/page
&p[images][0]=path to image
&p[title]=my custom title
&p[summary]=summery content”
target=”_blank”>
<img src=”path to image use as a link”
alt=”Share on Facebook” />
</a>

Advertisements