Another WordPress Development Blog

Share on Facebook code for WordPress


Since Facebook.com is the biggest and most used social media site you may want to give visitors the option to share your posts with their friends. In this case a “share on facebook” link becomes mandatory for any serious blog.

The things you need to do are not complicated.. Facebook is helping you by providing a link format for building such links. You just need to make sure that the target url has the following format.

http://www.facebook.com/sharer.php?u=<url to share>&t=<title of content>

Following this rule you can create numerous personalized icons or links that will fit your wordpress design.

To insert the “share to facebook” action in a wordpress post page use the code below :

<a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php?u=<?php echo get_permalink();?>&t=<?php echo get_the_title();?>">Chage with your link or image</a>
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>

Adjust the code above by inserting an image/icon or a custom text. Copy past the snippet after the_post(); instruction.

Random Posts

Leave a Reply